Uploading images to Cloudinary without specifying the image path in nodejs code
I am trying to upload files directly to Cloudinary using nodejs. I have gotten in to work successfully, but ONLY when I manually set the path of the image I am going to be upload, like so:
cloudinary.uploader.upload('./public/css/img/' + data.image)
but when I do this:
cloudinary.uploader.upload(data.image)
it does not work. A sample of my entire function is below. I need it to work like this because when I allow others (not on my local machine) to upload images, it will not work.
// collected image from a user
const data = {
image: req.query.image,
}
console.log(data)
// upload image here
cloudinary.uploader.upload(data.image)
.then((result) => {
// response.status(200).send({
// message: "success",
// result,
// });
console.log(result.secure_url)
-
Hi Gianluca,
To do so, you can:
- Use our Upload Widget.
- Create a form with an input_type_file on your side. When the form is submitted, you can pass the data via a POST to your backend and then call the code you already have to upload files to Cloudinary. There is a StackOverflow explaining all the steps before the upload to Cloudinary here.
Hope that helps,
Best,
Loic
Please sign in to leave a comment.
Comments
3 comments