problems uploading two or more images with uploader
Hello, I know that uploader is asynchronous but i don't know how implement it.
I have this code:
function upload2Cloudinary(req, res, next) {
req.imgURL = [];
cloudinary.config(config.cloudinary);
const cloudStream = cloudinary.uploader.upload_stream(
{
folder: 'animal-profile-images'
},
function (err, result) {
req.imgURL.push(result.url);
next();
}
);
for (const file of req.files) {
streamifier.createReadStream(file.buffer).pipe(cloudStream);
}
}
variable req.files has 2 or more images. The result is that the
program upload one image but only one. If I pass 3 images always
storage one of them. How can I resolve it? Thank you
-
Hi Alejandro,
Cloudinary uploader only accepts one file at a time, you can loop over the resources and call the uploader in the loop for every resource.
Regards,
Aditi
0 -
<script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) {; %} <tr class="template-download"> <td width="100px" align="center"> <span class="preview"> {% if (file.path) { %} <img src="/myproject/{%=file.path%}" width="100px"> {% } %} </span> </td> <td width="400px" align="center"> <p class="name"> {%=file.name%} </p> {% if (file.error) { %} <div><span class="label label-important">Error</span> {%=file.error%}</div> {% } %} </td> <td width="100px" align="center"> <span class="size">{%=o.formatFileSize(file.size)%}</span> </td> </tr> {% } %} </script>
0 -
Hey Alejandro Esteban, From where you got this code? I want something like this but don't know from where to get this. Please help me if possible for you. Thanks
0 -
Hi Ryan,
In order to better understand the issue, I need some more information.
Can I please ask you to provide more details about the problem you're encountering?You can also check out our documentation where we have code samples
https://cloudinary.com/documentation/node_integration
Looking forward to your response.
Best,
Akshay0 -
Hi Rubina,
I had shared some working examples of using upload_stream via NodeJS SDK in the following support thread:
Please take a look and let me know if those examples help?
0
Post is closed for comments.
Comments
5 comments