cloudinary_npm icon indicating copy to clipboard operation
cloudinary_npm copied to clipboard

Upload preset must be specified when using unsigned upload

Open topb-devops opened this issue 6 months ago • 14 comments

Bug report for Cloudinary NPM SDK

Describe the bug in a sentence or two.

Have been using Cloudinary uploader the same way for a long time, just within the past few days I am now getting: Upload preset must be specified when using unsigned upload

Even though I am passing in these at the options to the uploader:

Image

If you need the full name I can give, just wasn't sure if that could be sensitive at all.

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK [ ] Babel - Babel errors or cross browser issues [X] Performance - Performance issues [X] Behaviour - Functions aren’t working as expected (Such as generate URL) [ ] Documentation - Inconsistency between the docs and behaviour [ ] Incorrect Types - For typescript users who are having problems with our d.ts files [ ] Other (Specify)

Steps to reproduce

Using uploader.upload_stream pass in options that include a upload_preset, returns error: Upload preset must be specified when using unsigned upload

Versions and Libraries (fill in the version numbers)

Cloudinary_NPM SDK version Node - 2.6.0 & 2.6.1 NPM - 2.6.0 & 2.6.1

topb-devops avatar Jun 16 '25 22:06 topb-devops

Hi @topb-devops,

Can you please share your upload call? How do you run it? Also, are you using a javascript run time? (i.e. bun)

jroco-cloudinary avatar Jun 17 '25 08:06 jroco-cloudinary

Sure!

Here is the most recent implementation result, the previous one was also resulting in the same issue so I made some adjustments to try and test.

Node runtime:

const uploadToCloudinary = async (file: File, options?: UploadApiOptions): Promise<UploadResponse> => {
  const arrayBuffer = await file.arrayBuffer()
  const buffer = Buffer.from(arrayBuffer)

  return new Promise((resolve, reject) => {
    cloudinary.uploader
      .upload_stream(options, (error, uploadResult) => {
        if (error) {
          log.error({ error, options }, 'Error uploading file to Cloudinary')
          reject({ success: false, error })
          return
        }

        resolve({ success: true, result: uploadResult })
      })
      .end(buffer)
  })
}

Edit:

This is called throughout the application, and have been verifying that options are passed in properly with the logging statements.

topb-devops avatar Jun 17 '25 13:06 topb-devops

Hi @topb-devops ,

That error means that an upload API call was received that had neither a signature nor an upload_preset property containing the name of an upload preset that's allowed for an unsigned upload.

I tried to search the logs by the filename and could not find any information. Would you mind sharing the cloud name that you are using? If you are not comfortable sharing it here, please create a support request: https://support.cloudinary.com/hc/en-us/requests/new so that we can take a look at the error closely.

Thanks, Sree

skalahasti-cloudinary avatar Jun 17 '25 18:06 skalahasti-cloudinary

Hi @topb-devops ,

Looked into a cloud name that my colleague thinks that's the one. I see that there is no upload preset specified or there are no defaults in the Upload Settings in the UI for API calls.

{"cloud_name"=>"XXXX", "resource_type"=>"image"}

Can you please look into your code further and check the params?

Also, please create a support request: https://support.cloudinary.com/hc/en-us/requests/new so that we can take a look at the error closely.

Thanks, Sree

skalahasti-cloudinary avatar Jun 19 '25 01:06 skalahasti-cloudinary

Apologies for delay,

I can go through the UI and try and set a default preset and see if that fixes the problem.

As far as the actual code goes, I Have been logging out the options being passed directly to cloudinary.uploader.upload_stream and upload_preset is most definitely being passed in to the options parameter.

Edit: Cloud name being used is top-brokerage

topb-devops avatar Jun 25 '25 18:06 topb-devops

Thanks @topb-devops for confirming the cloud name.

Looking at the logs, I do see a successful request today with the following parameters via user_agent: CloudinaryNodeJS/2.6.1 (Node 22.6.0)

"folder"=>"XXXX", "filename_override"=>"XXXX.pdf", "timestamp"=>"1750877963", "upload_preset"=>"XXXX"

Please let me know if you can successfully upload via Node.js SDK methods now.

Thanks, Sree

skalahasti-cloudinary avatar Jun 25 '25 20:06 skalahasti-cloudinary

Issue appears to only happen sometimes. I Have an error entry from 1750874711587 (June 25, 2025 1:05pm) stating the same missing upload preset and log statement also printed out the parameters passed into options and it did include cloud_name.

Will continue to monitor now that I have the default set on the UI.

topb-devops avatar Jun 26 '25 13:06 topb-devops

Thanks @topb-devops . Based on our logs, I see that the upload preset wasn't passed along for the specified timestamp i.e. June 25th.

{"cloud_name"=>"top-brokerage", "resource_type"=>"image"}

Thanks, Sree

skalahasti-cloudinary avatar Jun 26 '25 20:06 skalahasti-cloudinary

So testing more locally, I determined that when trying to use upload_stream in the Bun runtime no matter what options being passed in, and I can get the logs again if you need them, it would always throw Upload preset must be specified when using unsigned upload then if I set the default in the UI for unsigned uploads, it would throw preset must be whitelisted for unsigned uploads

I Was able to get it all working by converting the files and images to base64 and using uploader.upload instead of uploader.upload_stream with the exact configuration.

Not sure why the 2 behave differently but that was how it got resolved for me.

topb-devops avatar Jun 27 '25 13:06 topb-devops

Hi @topb-devops ,

I see only from your staging cloud and not from prod cloud since the past 2 days with the error: "Upload preset must be specified when using unsigned upload".

Also, if we can get permissions to test against your cloud with the code you provided, that we help us debug even further.

Thanks, Sree

skalahasti-cloudinary avatar Jun 27 '25 23:06 skalahasti-cloudinary

Sure, you are welcome to test against the staging cloud. Let me know if theres anything else you may need provided.

topb-devops avatar Jul 01 '25 14:07 topb-devops

Hi @topb-devops,

From what I understand, Bun is a JavaScript runtime that can often run Node.JS code.

Cloudinary’s JavaScript SDK is intended for front-end (browser-based) use. For front-end uploads, you'll need to use an unsigned upload preset. Hence, the upload preset error.

So even though the code is called from a backend server using Cloudinary Node.JS APIs, it looks like the runtime is resolving it as a JavaScript request and failing.

Can you provide us with the public_id or file name of a previously failed upload?

Best Regards, John

jroco-cloudinary avatar Jul 02 '25 09:07 jroco-cloudinary

Same issue here. What needs to be done to get this fixed, since Vercel opened the floodgates on running Bun server side.

DmacMcgreg avatar Nov 18 '25 02:11 DmacMcgreg

Hi @DmacMcgreg, thanks for the information. I have raised this internally for us to discuss. We'll update you once we have more information to share.

jroco-cloudinary avatar Nov 18 '25 10:11 jroco-cloudinary