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
Comment actions -
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. -
Please see the answer here: http://support.cloudinary.com/entries/23997321-how-to-use-discard-original-filename-upload-API-parameter
-
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.
-
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?
-
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.
-
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=..... `
-
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
-
Hi Loic -
That URL fails for me: https://imgur.com/jrxFZWW
-
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
Post is closed for comments.
Comments
26 comments