How can i save image from my cloudinary account?
Hi,
If I have uploaded the image in my Cloudinary account and the image path will be like this "https://res.cloudinary.com/<cloud-name>/image/upload/version/file.jpg". I need to download/save the image into my local machine.
For example:
I can fetch the image URL using the following code,
cloudinary.url().type("fetch").imageTag(uploadedMap.get("url"))
Return the sample response as follows:
http://res.cloudinary.com//image/fetch/http://res.cloudinary.com//image/upload/version/file.jpg.jpg
the above URL comes from img tag like this <img src="url">
-
Hi Durga,
The example code you provided creates a new image tag sets its source to the URL for an image of type 'fetch' in your account ( see https://cloudinary.com/documentation/fetch_remote_images#remote_image_fetch_url for information about fetched URLs).
Then you're passing the URL of the original image in your account as the public_id, which means you're creating a second copy of the same image.
The fetched URL type is usually used to fetch an image from another server, transform it, and deliver it from your account ( like this, for example, which fetches the file from wikimedia and converts it to a 'cartoon' effect, resizes it, and sets the quality and format automatically: http://res.cloudinary.com/demo/image/fetch/w_1000,e_cartoonify,q_auto,f_auto/https://upload.wikimedia.org/wikipedia/commons/8/8b/Campsite_at_Mystic_Beach%2C_Vancouver_Island%2C_Canada.jpg )
If you want to save the original image, you can download the URL returned to you by the upload API (uploadedMap.get("url") in your code) directly - you don't need to make another call to our SDK or API once you have received or created the URL for the veresion of the image you want. In this case, if you're asking for the original, you can just request the `https://res.cloudinary.com/<cloud-name>/image/upload/version/file.jpg` URL and save it locally.
If you can let me know which language or Framework you're using, I can suggest some libraries or functions to download a specified URL.
Regards,
Stephen0 -
Hi Stephen,
When the upload process is completed and I got an URL like this 'https://res.cloudinary.com/<cloud-name>/image/upload/version/file.jpg.jpg'. from the following code
Map upload = cloudinary.uploader().upload(file,
ObjectUtils.emptyMap();
String url = upload.get("url");I need to convert this URL into the File and wants to upload into S3. I just convert this URL and uploaded but I couldn't able to view this image instead it returns text file. (extension will be .jpg)
Language: Java
0 -
Hi Durga,
There are many ways to download a file from a URL in Java, and you may also be able to use Amazon's API/SDK to upload to the S3 bucket directly using the URL, but this isn't something I'm familiar with
To download a file, the most simple way which requires no additional libraries is to use the java.nio package
There's an example of that and many other methods for downloading files here: https://stackoverflow.com/q/921262/21062Using the first answer there, your code may look like this:
Map upload = cloudinary.uploader().upload(file,ObjectUtils.emptyMap();URL imageURL = new URL(upload.get("url")); ReadableByteChannel rbc = Channels.newChannel(imageURL.openStream()); FileOutputStream fos = new FileOutputStream("image.jpg"); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);To upload that file to Amazon, you can use Amazon's SDK. There's an example in Amazon's documentation here: https://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjSingleOpJava.html
Regards,
Stephen
1
Post is closed for comments.
Comments
3 comments