How can I deliver an image as an attachment?

Follow

Comments

5 comments

  • Avatar
    Billy Silva

    Perfect, exactly what I needed!  This stuff should all go into the documentation!

    0
    Comment actions Permalink
  • Avatar
    Yaka App

    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

    0
    Comment actions Permalink
  • Avatar
    Maor Gariv

    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.

    0
    Comment actions Permalink
  • Avatar
    Mukesh Saxena

    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?

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.