-
Notifications
You must be signed in to change notification settings - Fork 125
add: guide for delivering remote images #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Waqibsk
wants to merge
4
commits into
cloudinary-community:main
Choose a base branch
from
Waqibsk:Feature/docs/guide-delivering-remote-images
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−0
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import Head from 'next/head'; | ||
import CodeBlock from '../../components/CodeBlock'; | ||
import OgImage from '../../components/OgImage'; | ||
import Video from '../../components/Video'; | ||
|
||
|
||
<Head> | ||
<title>Remote Images - Next Cloudinary</title> | ||
<meta name="og:title" content="Delivering Remote Images - Next Cloudinary" /> | ||
<meta name="og:url" content={`https://next.cloudinary.dev/guides/remote-images`} /> | ||
</Head> | ||
|
||
<OgImage title="Remote Images" twitterTitle="Delivering Remote Images" /> | ||
|
||
# Working with Remote Images | ||
|
||
You can leverage Cloudinary's powerful transformation and delivery features even for images not stored in your Cloudinary account. | ||
|
||
Next-cloudinary provides two primary methods for working with remote images: | ||
|
||
## Method 1: Fetching Remote Images On-the-Fly | ||
|
||
The `Fetch` delivery method allows you to use a remote image URL as a source for the `CldImage` component. | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Cloudinary will fetch the image, apply transformations, cache it on the CDN, and deliver it, all without storing it in your Media Library. | ||
|
||
This is the simplest way to get started with remote media. | ||
|
||
### Example: | ||
|
||
To use this method, provide the remote image URL to the `src` prop and add the `deliveryType="fetch"` prop | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<CodeBlock> | ||
Waqibsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```jsx copy showLineNumbers | ||
import { CldImage } from 'next-cloudinary'; | ||
|
||
<CldImage | ||
width="400" | ||
height="400" | ||
src="your image url " | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
deliveryType="fetch" | ||
// Apply transformations like any other Cloudinary image | ||
Waqibsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
alt="Next.js Logo" | ||
/> | ||
``` | ||
</CodeBlock> | ||
This will generate a Cloudinary URL prefixed with `/image/fetch/`, which instructs Cloudinary to retrieve the image from the source URL | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Method 2: Auto-Uploading Remote Images | ||
|
||
This method automatically uploads an image from a remote source to your Cloudinary Media Library the first time it's requested. | ||
|
||
Subsequent requests will serve the now-stored Cloudinary asset. This is a powerful Cloudinary feature that works seamlessly with next-cloudinary. | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
### Use Cases | ||
|
||
- Migrating an existing media library from a service like S3 to Cloudinary without downtime | ||
- Permanently storing and managing remote assets in Cloudinary | ||
- Building a media library from a trusted, remote source over time | ||
|
||
### How to Set Up Auto-Upload Mapping: | ||
|
||
1. Navigate to your Cloudinary settings: Go to `Settings` >` Upload`. | ||
2. Find the `Auto upload mapping` section: Here you will define the mapping. | ||
3. Create a new mapping: | ||
- **Target Folder**: : A virtual folder name to use in your src prop (e.g., `s3-images`). | ||
- **Source URL prefix**: Paste the base URL of your remote image storage (e.g., `https://my-s3-bucket.s3.amazonaws.com/images/`). | ||
4. Save your changes | ||
|
||
Waqibsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
### Example Usage: | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<Video | ||
title="Upload Images & Videos to Cloudinary Automatically with Auto Upload" | ||
url="https://www.youtube.com/watch?v=LJhsn5A0PFE" | ||
/> | ||
|
||
|
||
|
||
### Implementation with `CldImage` | ||
|
||
Once your mapping is configured, construct the src prop by combining your mapped folder with the remote image's path | ||
Waqibsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<CodeBlock> | ||
Waqibsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```jsx copy showLineNumbers | ||
import { CldImage } from 'next-cloudinary'; | ||
|
||
// Remote URL: https://my-s3-bucket.s3.amazonaws.com/images/product-image.jpg | ||
// Mapped Folder: s3-images | ||
|
||
<CldImage | ||
width="960" | ||
height="600" | ||
src="s3-images/product-image.jpg" | ||
alt="An image that will be auto-uploaded" | ||
/> | ||
``` | ||
</CodeBlock> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.