Cloudinary supports delivering uploaded images as attachments using their original file names.
You can use the flags
transformation parameter to attachment
, or add fl_attachment
to transformation URLs.
The original file name of all newly uploaded images is now stored on our side for this purpose (for previously uploaded images the public ID would be used).
You can set the flags transformation parameter to attachment, or add fl_attachment to transformation URLs.
Here's a sample uploaded image delivered inline:
http://res.cloudinary.com/demo/image/upload/v1362144095/sample_attachment.jpg
Same uploaded image with the attachment flag, downloaded as the original file name ('Custom File Name'):
http://res.cloudinary.com/demo/image/upload/fl_attachment/v1362144095/sample_attachment.jpg
When using our Ruby GEM, simply add :flags => :attachment
when building transformation URLs of uploaded images.
UPDATE: You can now change the name of the file on download by using fl_attachment:<new_filename>.
For example, to change the original file name to "new_sample" on download you can do the following:
Comments
5 comments
I'm using fl_attachment to download transformation but it is downloading in webp format. I want to download in jpg format. What should I need to do?
As raw files cannot be transformed, the default behaviour is to download the document. For example,
http://res.cloudinary.com/demo/raw/upload/SinglePageSample_kdca7x.docx
For PDFs you can set the type to image and use the fl_attachment parameter, as usual.
Thanks, please, how to do same thing for non image document ?
So, get an url like http://res.cloudinary.com/demo/????/upload/fl_attachment/v1362144095/sample_attachment.everything
Perfect, exactly what I needed! This stuff should all go into the documentation!
Hi Mukesh,
If you're applying a specific fetch format (f_auto, f_webp) or changing the extension of the image in your URLs at the same time as requesting the fl_attachment transformation then that would explain why you're getting a WebP image when downloading.
If your originals are already in JPG format then you should ensure that the extension for the public_id stays as JPG and that there aren't any explicit fetch format transformations.
For example, the following "sample" image is already in JPG format within our Demo account.
I can deliver the image as an attachment by just including the fl_attachment transformation in the URL and keeping the existing extension untouched:
https://res.cloudinary.com/demo/image/upload/fl_attachment/sample.jpg
On the other hand, let's say the image was in a different (PNG) and I want to download it as a JPG, I can go ahead and set the fetch format (f param in URLs ) to JPG:
https://res.cloudinary.com/demo/image/upload/fl_attachment,f_jpg/sample.png
Please sign in to leave a comment.