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)
0
-
Hi,
When using upload it will search the image in the same directory as the upload call.
You can specify the full path (as you provide in your first example or call the upload from the same folder as the image.
Hope that helps,
0 -
Hi Shirly.
I want to allow multiple users to use this as well, so they wouldn't be using my local machine. I was looking to be able to upload the image they select from their local machine and then upload it to Cloudinary. Is this possible?
0 -
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
0
Post is closed for comments.
Comments
3 comments