File extension not stored in public Id

Comments

9 comments

  • Avatar
    Yakir Perlin

    Hi Christian,

    I'm sorry for the late response.

    Could you please try to add "use_filename:true" :

    cloudinary.v2.uploader.upload("<file_path>", {use_filename :true, resource_type:'raw'}, function(result,err) {

    console.log(result)
    });
     
    Please let me know if it helps you.
     
    Best,
    Yakir
    0
    Comment actions Permalink
  • Avatar
    Parik Panchal

    @Yakir Will this ensure uniqueness of filename as well? So if I upload 2 files of same name of "audio.wav", how will these files stored?

    0
    Comment actions Permalink
  • Avatar
    Marissa Masangcay

    Hi Parik,

    When you use the parameter 'use_filename: true'  the file name is normalized and random characters are appended to ensure uniqueness so if you upload two files with the same name they would be given two different public IDs. However, if you don't want this feature you can also include the parameter 'unique_filename: false' and then random characters won't be appended to the public ID.

    Please note that if you use both the parameters 'use_filename: true' and 'unique_filename: false' and you upload two files with the same name then the original file will be overwritten by the newly uploaded file. If you don't want this behavior you can also include the parameter 'overwrite: false' so that it will not replace the original resource.

    I hope this helps!

    0
    Comment actions Permalink
  • Avatar
    Sunday

    I tried saving a file with extension on .doc and .docs but instead of getting url with the original file name and the extension, I got a different result at shown below. Uploading pdf file works perfectly. Please what may be the error.

    result:
    { public_id: 'jextaly/file_jwv888',
    version: 1581601783,
    resource_type: 'raw',
    created_at: '2020-02-13T13:49:43Z',
    tags: [],
    bytes: 141824,
    type: 'upload',
    placeholder: false,
    url:
    'http://res.cloudinary.com/raw/upload/v1581601783/jextaly/file_jwv888',
    secure_url:
    'https://res.cloudinary.com/raw/upload/v1581601783/jextaly/file_jwv888',
    access_mode: 'public',
    original_filename: 'file' }

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi,

    Does your original file contain an extension prior to uploading? By default, when uploading raw files, we will take the original extension of the file, therefore, if the original file is missing one it will not get assigned.

    In addition, could you please share your upload code, are you using the upload method or upload_stream etc?

    0
    Comment actions Permalink
  • Avatar
    Sunday

    @Aleksandar, my original file contains the .doc or Docx extensions. .pdf extensions work perfectly but .doc and .docx does not work after upload from my Node server 

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Thanks for these details. The PDFs work due to them being recognised and treated as Image files rather than Raw. May I please ask you to share the code you are using to upload and the parameters you are passing?

    0
    Comment actions Permalink
  • Avatar
    Sunday

    ```


    function uploadToCloudinary(buffer) {
    returnnewPromise((resolve, reject)=> {
    constoptions={
    folder: cloudinaryFolder,
    resource_type: "raw",
    // use_filename:true,
    overwrite: false
    // allowed_formats: ['jpeg', 'jpg', 'png', 'pdf','doc', 'docx', 'txt']
    }
    conststream=cloudinary.v2.uploader.upload_stream(
    options,
    (err,result)=>{
    console.trace({result})
    if(err) return reject(err)
    return resolve(result)
    }
    )
    intoStream(buffer).pipe(stream)
    })
    }
    ```
    0
    Comment actions Permalink
  • Avatar
    Eyal Katz Talmon

    Hi,

    In order for us to further investigate, it would be greatly helpful if you could kindly open a support ticket at support@cloudinary.com. Please attach a relevant file that may help us to reproduce the issue. Any additional information would be appreciated as well. Thanks!

    0
    Comment actions Permalink

Please sign in to leave a comment.