How to upload images while keeping their original filenames?

By default, when using our API for uploading, Cloudinary will set a randomly generated public ID for the uploaded image.

You can set the use_filename parameter to true to set the uploaded image's public ID to be as the original file's name. However, a random string is appended to the image's public ID to ensure uniqueness. For more information:
http://support.cloudinary.com/entries/26977753-Why-does-the-public-ID-include-additional-characters-appended-to-the-original-file-name-

In addition, Cloudinary allows you to set the image's public ID as the original filename, without appending random characters at the end of it.
When setting the use_filename parameter to true you can also set the unique_filename (which is by default set to true) to false. This will tell Cloudinary to not add random characters to the public ID. Here's an example in rails:

Cloudinary::Uploader.upload("my_image.jpg", :use_filename => true, :unique_filename => false)

Note that if you already have an image stored in your account that has that exact public ID, it will be overwritten.

Have more questions? Submit a request

Comments

  • Avatar
    cuma elp

    i think it not really keep the file name as it's current name** if** it has more period(s) other than it's file extension. I've test it today, the period will changed into underscore.

    for example : image.name.png=>** image_name**.png

    is there any solution to keep it as it is? it's real name with period(s) in it.

  • Avatar
    Nadav Ofir

    In Cloudinary we, indeed, replace periods with underscores as part of our naming conventions. Although, you can by-pass it by either explicitly supply the public_id, e.g., (in rails):

    Cloudinary::Uploader.upload(" my.image.jpg", :public_id => "my.image")

    Or, post-upload, rename the image using the Media-Library or the API, e.g., (in rails):

    Cloudinary::Uploader.rename("my_image","my.image")

  • Avatar
    cuma elp

    oh i see. so i supposed to specifically fill in the public_id with image file name

  • Avatar
    Nadav Ofir

    Did it work for you?

    If there is any thing else we can assist you with, please feel free to open a ticket:

    http://support.cloudinary.com/tickets/new

     

  • Avatar
    Itay Taragano

    UPDATE

    The system was just updated to support dot-included filenames, so use_filename will not replace dots with underscores.

  • Avatar
    ankit parsana

    Hi

    I am trying to upload the file keeping the original filename. Please check what I am doing wrong.

    echo cl_image_upload_tag('test', array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true),"folder" => "my_folder","unique_filename" => false));

  • Avatar
    Itay Taragano

    I couldn't find the use_filename parameter in the code you shared.

    Please try the following and let me know if this works for you:

    echo cl_image_upload_tag('test', array("tags" => "direct_photo_album", "callback" => $cors_location, "html" => array("multiple" => true),"folder" => "my_folder","use_filename" => TRUE, "unique_filename" => FALSE));

  • Avatar
    Mirta Arambulo

    Hi Itay

    I am using this in my view on RoR
    <%= f.attachinary_file_field :file, as: :attachinary, cloudinary: {use_filename: true, unique_filename: false} %>

    but it doesn't work. It is always changing the document name. Could you help me please?

  • Avatar
    Mirta Arambulo

    For some reason the underscore characters are deleted from my comment.

    this is how i have
    http://screencast.com/t/PpWmDIgmQ7co

  • Avatar
    Maor Gariv

    Hi,

    Sorry for the very late reply, we have noticed that this request was left unattended. I see that your issue was handled through a support ticket with Itay:)

Powered by Zendesk