3
votes

I'm having some difficulty getting uploads to the correct folder. If I specify:

cloudinary.uploader.upload(filePath, {
  folder: 'test-directory'
});

I'm following the Node integration guide at: http://cloudinary.com/documentation/image_upload_api_reference#upload

I created the "test-directory" ahead of time. The image uploads successfully, but always goes to the root of my media library.

I have "auto create folders" enabled in my account settings.

Here's a sample upload response from Cloudinary:

{
  public_id: 'we1yjvlpxc1qtuf1oaqe',
  version: 1503236713,
  signature: '37edbc2b19ea72b75298acce8075f9e8ddb12d09',
  width: 675,
  height: 37,
  format: 'jpg',
  resource_type: 'image',
  created_at: '2017-08-20T13:45:13Z',
  tags: [],
  bytes: 602,
  type: 'upload',
  etag: 'b5522ae652340881b213c46c035d0aed',
  url: 'http://res.cloudinary.com/alsoicode/image/upload/v1503236713/we1yjvlpxc1qtuf1oaqe.jpg',
  secure_url: 'https://res.cloudinary.com/alsoicode/image/upload/v1503236713/we1yjvlpxc1qtuf1oaqe.jpg',
  original_filename: 'test_r6_c1'
}

I have also tried adding the folder name to the public_id option, but that hasn't worked either.

What am I doing wrong?

2
Can you share the public_id returned in the upload response?Maor.G
@Maor.G I've added a complete upload response.Brandon
Cloudinary also doesn't seem to be respecting other options like use_filename, as the uploaded resources all have automatically generated filenames. The uploads are successful, but no options are applied.Brandon

2 Answers

8
votes

Add the v2 to have the upload parameters' order as (file, options, callback) -

cloudinary.v2.uploader.upload(filePath, {
 folder: 'test-directory',
 use_filename: true
});

Without it the order is (file, callback, options) -

cloudinary.uploader.upload(filePath,function(res){console.log(res);},{
 folder: 'test-directory',
 use_filename: true
})
0
votes
  • upload parameters' order as (file, options, callback) *

    cloudinary.uploader.upload(
              file,
              {
                  folder: 'directory',
                  use_filename: true
              },
              function (error, result) {
                  if (result.url) {
                      resolve({ url: result.url })
                  } else {
                      reject({ message: "image upload fail", error })
                  }
              },
    
          );