Can I upload files to a folder while keeping their original file names?

Follow

Comments

19 comments

  • Avatar
    Raya Straus

    Hi Khaled,

    You can specify the folder you wish to upload to in the public_id. For example, using formdata- 

    The image will be given the public id "my_folder/mysample' meaning it will be in the folder named "my_folder"

     

    var formdata = new FormData();

    formdata.append('file', file);
    formdata.append('cloud_name', '<cloud_name>');
    formdata.append('resource_type', 'image');
    formdata.append('upload_preset', '<upload_preset>');
    formdata.append('public_id', 'my_folder/mysample')

    var xhr = new XMLHttpRequest();
    xhr.open('POST', "https://api.cloudinary.com/v1_1/<cloud_name>/image/upload",true);


    xhr.send(formdata);

     

    1
    Comment actions Permalink
  • Avatar
    MichaelPrenz

    Hello Itay,

    I use the Auto Upload Feature to get an image.
    I want the image name as Public ID and enabled it in the settings.

    Now I want to use THIS image as watermark and use it with the overlay parameter "l".
    But because I have to choose a folder for Auto upload,
    the Public ID always containts the foldername and "/" in it`s name, which I can not use with the overlay parameter.

    How can I do it this way ?
    I do not want to put hands on the prozess, (the images changes, no solid watermark ! - no renaming e.g. manuell)
    Is there a way to choose the root folder for auto upload ?
    Or is there an "Auto" Rename Function to get rid of the (/) in the name ?

    Thank you so much for your help !

    Regards

    0
    Comment actions Permalink
  • Avatar
    Daniel Mendoza

    @Naw

    If you would like to upload to a specific folder in Cloudinary via C#, add the Folder parameter as part of the ImageUploadParams:

     

    var uploadParams = new ImageUploadParams() {
       File = new FileDescription("img1", img1.InputStream),               
    Transformation = 
    new Transformation().Width(688).Height(458).Crop("fit").FetchFormat("png"),
      Folder = "folder
    }; 
    0
    Comment actions Permalink
  • Avatar
    Philipp Gärtner

    Goal: My goal ist to upload images and a) keep the original name and b) know the exact URL path.

    I set the Upload preset to:

    • Overwrite: true
    • Use filename or externally defined public ID: true
    • Unique filename: false
    • Delivery type: upload
    • Access mode: public

    When I upload images using the Dashboard Media Library my images keep the original filename (which is great) but cloudinary adds a unique ID  "v1585290075" into the URL. 

    https://res.cloudinary.com/xxxxx/image/upload/ => v1585290075 <= /2020-03-27-ee-apps/xxxxxxx.png

     

    This unique ID prevents me from knowing the exact URL. 

     

    Question: How can I avoid this unique ID??

     

    Cheers, Philipp

    0
    Comment actions Permalink
  • Avatar
    Itay Taragano

    UPDATE
    You can now set "Use file name in Media Library" in your account's Upload settings page to tell Cloudinary to not add random characters in the root directory either.

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi Philipp,

    The v123456789 is not part of the public_id and URLs will work with or without it. It represents the upload time of the asset. It is used as one way of delivering the latest version and avoid any cached copies that may reside on the CDN. The other way would be to use CDN invalidation to clear any cached copies when using URLs without a version number.

    The API will always return the URLs with the latest version number, but you don't have to use those and can build the URLs yourself, or use the SDK helper methods we provide to build the URLs for you. However, if you would like to use URLs without a version number, then we would need to update your account settings so that the URLs we send for invalidation at the CDN match the URL format you are using. By default, the URLs that are sent for invalidation use a 'v1' as the version number for resources in folders and no version number for resources in the root. Please see the below article with details on these invalidation options -

    https://support.cloudinary.com/hc/en-us/articles/360001208732-What-URL-conventions-are-invalidated

    Afterwards, I suggest opening a ticket with us at https://support.cloudinary.com/hc/en-us/requests/new so that we can configure your account to invalidate URLs without a version number. Then you can build the URLs without one and upon deleting and overwriting existing images the CDN cache would be purged of any cached copies.

     

    0
    Comment actions Permalink
  • Avatar
    Frank Bruce

    If I upload to an folder, it includes the folder in the image URL, but if I check on the Media Library the image is there with the folder in its url, but the new folder has not been created. If I then create the new folder using the create folder button, it creates the folder and any images can then be viewed under that folder.

    It would be nice for the folder to automatically be generated, or is there a way via the API?

    0
    Comment actions Permalink
  • Avatar
    Itay Taragano

    Hi Frank,

    You can go to your  Settings page and enable Auto-create folders.

    This will automatically synchronize the resources and folders created by the API with the Media library.

    0
    Comment actions Permalink
  • Avatar
    Robert Jackson

    Is this "folder" parameter available for the PHP API?  I do not see it listed in the API Documentation http://cloudinary.com/documentation/php_image_upload

    I guess I can just try it.  Also how many images can a folder hold before a new folder should be created?  I'll be processing the images and compressing them by 75% first so the files should be fairly small.

    0
    Comment actions Permalink
  • Avatar
    Itay Taragano

    Hi Robert,

    While it isn't documented yet, indeed the folder parameter is available for the PHP API as well. Here's an example:

    \Cloudinary\Uploader::upload('my_image.jpg', array("folder" => "my_folder"));

    You can store as many images as you need, there is no limit per folder.

    0
    Comment actions Permalink
  • Avatar
    Glenn Goodrich

    So, could I use this to separate staging and production environments? Or do you have another suggestion for that?

    0
    Comment actions Permalink
  • Avatar
    Robert Jackson

    Awesome thanks. I am about to try this. My local file structure will be different from my cloudinary file structure.

    0
    Comment actions Permalink
  • Avatar
    Itay Taragano

    You can indeed use folders to separate the resources from staging and production environments. 

    However, we usually recommend to have different accounts for staging and production, and copy required images from one account to the other. You can use Cloudinary's Auto-migration feature which you can have your staging account syncing with your production automatically only for your used images. Note that all images of production account will be stored within a folder in your staging account.

    For more information:

    http://cloudinary.com/blog/how_to_automatically_migrate_all_your_images_to_the_cloud

    From our Advanced Extra plan, we support having our multi-accounts feature which allows you to manage up to five different accounts via a single login, where all accounts share the master account's usage quotas.

    0
    Comment actions Permalink
  • Avatar
    ankit parsana

    Hi I am uploading images from the media library and I dont want the appended unique characters for the original file name. Is there any setting for that from the interface.

    0
    Comment actions Permalink
  • Avatar
    Itay Taragano

    When you upload images via the Media library to the root directory, Cloudinary indeed automatically adds a short random string to the 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-

    However, when you upload into a folder, the extra string is not added to the public ID.

    You can also tell Cloudinary to not add the extra string when uploading the API. For more information:

    http://support.cloudinary.com/entries/25830181-How-to-upload-images-while-keeping-their-original-filenames-

    0
    Comment actions Permalink
  • Avatar
    Tristan

    Hello Cloudinary,

    How could I specify the upload folder in Python 3 ?

    example:


    @menu_ctrl.route('/', methods=['POST'])
    def upload(gallery):
    gallery= request.args.get('gallery');
    if request.method == 'POST':
    for f in request.files.getlist("file"):
    upload_result = upload(f, folder=gallery)
    return SuccessResponse({}, 201)

     

    Tristan,

    Best regard!

    0
    Comment actions Permalink
  • Avatar
    Naw Latt

    Hi, i want to upload image to my created custom folder with C#

    How to populate with C#.

    Here is my code

     

    var uploadParams = new ImageUploadParams()
    {
    File = new FileDescription("img1", img1.InputStream),
    Transformation = new Transformation()
    .Width(688).Height(458).Crop("fit").FetchFormat("png")
    };
    var upLoadResult = cloudinary.Upload(uploadParams);
    string publicID = upLoadResult.PublicId;
    string ImageURL = upLoadResult.Uri.ToString();

     

     

    0
    Comment actions Permalink
  • Avatar
    Khaled BK

    Hi, is there any example using JS ? 

    0
    Comment actions Permalink
  • Avatar
    Nadav Ofir

    Hi Michael,
    Here's an article that explains how to solve the folders hierarchy matter:
    https://support.cloudinary.com/hc/en-us/articles/202521352-How-to-use-an-image-from-a-sub-folder-as-an-overlay-
    Moreover, you can map your root directory by putting a slash ("/") inside the "Folder" field.

    0
    Comment actions Permalink

Please sign in to leave a comment.