Force "Save As" Dialog
AnsweredHi,
I'm trying do give users of my site the ability to save a picture with just clicking it and then get prompted with an save as... dialog instead of being forced to right click,...
Using CakePHP:
if ($imageData["Image"]["active"] && $imageData["Image"]["cloudinary"]!='') {
$image_link = "http://res.cloudinary.com/myname/image/upload/" . $imageData['Image']['cloudinary'] . ".jpg";
$size = @getimagesize($image_link);
$fp = @fopen($image_link, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
header("Content-Length: " . filesize($image_link));
header("Content-Disposition: attachment; filename=$image_link");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
fpassthru($fp);
die;
}
}
Download starts but all I get is a black image with the red text "Ungültiges Bild" (~ Invalid Image).
I think this is some cross-domain problem. Any ideas?
Yours,
Ludger
-
Official comment
Hey Martin,
We recently added the ability to change the file name with using fl_attachment.
For example, the following link will download the image "newname.jpg":
Please let me know if it works for you.
Cheers,
Yakir
-
Hi Ludger,
Cloudinary supports delivering uploaded images as attachments using their original file names.
You can use the
flags
transformation parameter toattachment
, or addfl_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 PHP, simply add
"flags" => "attachment"
when building transformation URLs of uploaded images.0 -
is it possible to force the use of the id instead of the upload filename? Since the images are user-uploaded, the filename could contain private information.
0 -
Hi Ludger,
You can set the
discard_original_filename
upload API parameter totrue
for making the files being downloaded as attachment don't use the original file name.0 -
Thank you,
can you tell me how to incorporate this parameter when building the upload string and signature manually?
0 -
Please see the answer here: http://support.cloudinary.com/entries/23997321-how-to-use-discard-original-filename-upload-API-parameter
0 -
Is it possible to define in the URL what the filename should be when it's downloaded?
0 -
Currently, we support either using the original uploaded resource's filename or the Cloudinary-defined public_id.
We'll consider supporting pre-definition of the downloaded file in the future.
0 -
Okay thanks Itay. For now, we'll need to proxy the download through our servers to enforce a filename that makes sense to the user.
0 -
Hi Oliver,
Thanks for the update. As an alternative, if the new filename is a string that doesn't change often, you may want to consider simply renaming the public_id of the resource before requesting it. If so, make sure the `discard_original_filename` flag is included at the upload's parameters.
0 -
I'm reluctant to change the public_id of a resource just to push a specific filename to the user. Feels a bit heavy-handed, you know?
0 -
Makes Sense, Oliver. We'll be happy to update here once we end up supporting an alternative in the future.
0 -
Okay. I'll be waiting patiently :)
0 -
Any update on this?
We have the same request:
On our website we would like to be able to download images.
By using the parameter `fl_attachment` we achieved this.
Unfortunately enabling this 'attachment' parameter, this results in downloading the file with the original file name. (As mentioned here: https://support.cloudinary.com/hc/en-us/articles/202521252-How-can-I-deliver-an-image-as-an-attachment-)Is there a possibility to make use of the 'attachment' parameter in combination with the 'suffix' option. Which would result in a forced download with a custom name instead of the original name?
0 -
Hi Frederik,
This is still on our to-do list to support. While there's no ETA for this at the moment, we'll definitely update here as soon as such a feature becomes available.
0 -
This feature is very usefull for us and will save a lot of time for many cloudinary users, who manually have to rename downloaded. I already opened an related issue #59925, where content-disposition filename is lost in URL fetching.
Feature request: Allow optional definition of filename. (addition to public-id)
If user opens a cloudinarey image url and wants to download it, you must add this optional filename as content-disposition filename header to the response. Automatic URL fetching shall save this new filename property automatically from original content-disposition.
0 -
Hi Marco,
You are absolutely right, and our Product Team is working on that.
We'll update here as soon as such a feature becomes available.
Best,
Yakir
0 -
Any progress/ETA on the custom filename feature?
0 -
Generally it works, but:
- I can't use a dot in filename e.g. ... `fl_attachment:new%23name` ... or `fl_attachment:new.name`
- I can't change the extension, but maybe that's a security feature (very minor issue)
- There is no corresponding fl_inline parameter to send `content-disposition: inline, filename=..... `
2 -
Yes the corresponding fl_inline is also required. Our users want to open a PDF in a new tab / window and then decide if they need to download it - with the new name.
0 -
Hi Marco,
You can show your image and add a button to download the image.
If the user would like to get the image he can then press the download and get the fl_attachment:my-image image.
Please let me know if that answered your question,
0 -
Amazing to see this is available now. Any chance there will be support for adding a period? We want to force file downloads like "file.01"
0 -
Hi Oliver,
We do support the dot symbol in the fl_attachment flag by using its double URL escaped version: %252E. And here is an example: https://res.cloudinary.com/demo/image/upload/fl_attachement:file%252E01/sample.png
Please let me know if that helps.
Best,
Loic
0 -
Hi Loic -
That URL fails for me: https://imgur.com/jrxFZWW
0 -
Hi Oliver,
My bad, an `e` appeared in `attachment`, you can try this link : https://res.cloudinary.com/demo/image/upload/fl_attachment:file%252E01/sample.png
Please let me know if that helps.
Best,
Loic
0 -
Awesome thanks so much!
0
Post is closed for comments.
Comments
26 comments