cloudinary_npm icon indicating copy to clipboard operation
cloudinary_npm copied to clipboard

Unable to upload multiple images to cloudinary

Open slim-hmidi opened this issue 9 years ago • 13 comments

I'm trying to upload multiple images to cloudinary:

const cloudinary = require('cloudinary');
const path = require('path');

const imagePath = path.join(__dirname,'/test','/*.png');
cloudinary.config({
    cloud_name: '****',
    api_key: '******',
    api_secret: '*******'
})

cloudinary.uploader.upload(imagePath, function(result) { 
    console.log(result) 
  });

I got this error message:

{ error:
   { Error: ENOENT: no such file or directory, open '/home/user1/cloudinary/test/*.png'
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/home/user1/cloudinary/test/*.png' } }

The program works with a single image. How can I do to upload multiple images in the same time?

slim-hmidi avatar Nov 28 '17 14:11 slim-hmidi

Hi, You can iterate through the list of images in a loop and upload the images one by one. cloudinary.uploader.upload() uploads one image at a time. For client side uploads we have a upload widget where you can upload multiple images. For more information:https://cloudinary.com/documentation/upload_widget#quick_example

aditimadan-Cloudinary avatar Nov 28 '17 23:11 aditimadan-Cloudinary

So no way to upload it simultaneously ?

slim-hmidi avatar Nov 29 '17 04:11 slim-hmidi

While our upload API currently only supports a single file upload at a time, it does have a high concurrency rate (of about 40-50 concurrent calls) so you can use multi-threads to upload many files at once. You can also use asynchronous calls, and tell Cloudinary to do the upload in the background by adding the async parameter and setting it to true.

aditimadan-Cloudinary avatar Nov 29 '17 20:11 aditimadan-Cloudinary

Closing this issue due to the time elapsed. Please feel free to either re-open the issue, contact our support at http://support.cloudinary.com or create a new ticket if you have any additional issues.

roeeba avatar Sep 21 '18 18:09 roeeba

Im trying the way you said and it is not working, got the same message, error: [Error: ENOENT: no such file or directory,

code on backend: const express = require('express'), router = express.Router(), multerUploads = require('../middleware/multer.config'), cloudinary = require('cloudinary').v2, cloudinaryconfig = require('../middleware/cloudinary.config'), PublicacionModel = require('./publicaciones.model');

cloudinary.config({
    cloud_name: cloudinaryconfig.cloud_name,
    api_key: cloudinaryconfig.api_key,
    api_secret: cloudinaryconfig.api_secret,
})

router.route('/registrar_publicacion') .post( multerUploads, (req, res) => {

    console.log(req.body);
    for(let i=0; i<req.body.length; i++){
        let imagePath = req.body[i].path;

        cloudinary.uploader.upload(imagePath)
        .then( (res) => {
            console.log(res);
        })
        .catch( (err) => {
            console.log('error');
            console.log(err);
        })
    }

on the backend I'm receiving the path of the images, like image.png, dont know how to get the full path like "myPC/documents/folder/image.png", maybe that the issue?

isaacSolano avatar Jul 14 '19 02:07 isaacSolano

Hi @isaacSolano , I saw you opened the same issue on request 287, you are welcome to look at the answer there.

michalkcloudinay avatar Jul 14 '19 12:07 michalkcloudinay

Thanks for answering, in this case the front end only provides me an object with the path property for each file, the req.body looks like this. req.body { image1: picture1.png image2: picture2.png }

on the front end I'm using dropzone , still it doesnt give me the full path of the file, on the front end I only have "picture.png" for the path property on the file object

isaacSolano avatar Jul 14 '19 13:07 isaacSolano

Hi @isaacSolano,

If you want to upload from server side you will have to specify a full path (or any other data upload options). If dropzone or any other service you are using cant supply this data, I can suggest an alternative, to upload directly from your front-end, by using one of these options:

  1. Cloudinary's Upload Widget for unsigned uploads without using server side. This is a complete, interactive user interface that enables to upload files from a variety of sources to your website or application. read more about it here.

  2. Direct uploading from the browser, can be used for signed upload, through server-side. It is easy to integrate with your code. More info here.

michalkcloudinay avatar Jul 15 '19 09:07 michalkcloudinay

Hi @michalkcloudinay Im using the unsigned upload preset now, i have this issue when using an unsigned upload_preset: error: Upload preset must be whitelisted for unsigned uploads when using unsigned presets, the code sc

Important: the upload preset i'm using is is unsigned already

isaacSolano avatar Jul 15 '19 11:07 isaacSolano

"Upload preset must be whitelisted for unsigned uploads" is usually when you try and use signed preset instead of unsigned. Can you please open a support ticket here:https://support.cloudinary.com/hc/en-us/requests/new and share your cloud name and upload preset and I will be able to debug this further.

aditimadan-Cloudinary avatar Jul 15 '19 21:07 aditimadan-Cloudinary

@aditimadan-Cloudinary Ticket submitted, thank you guys for your help and assistance. 👍

isaacSolano avatar Jul 15 '19 23:07 isaacSolano

for those, who are using streams, here is quick and simple way of doing this: https://gist.github.com/sinnrrr/58901f7cdf77e299dc00ed23f362fcb8

sinnrrr avatar Mar 28 '21 20:03 sinnrrr

Hello, You need to put "Overwrite" to "Off" in all others presets So you can use the preset you want

DylanP97 avatar Apr 11 '23 10:04 DylanP97