I'm working on an application using Node JS, Formidable, and Cloudinary dependencies that lets users upload images to a Cloudinary database.
Users will upload images from a multipart form, and I want the fields to become variables to be passed to the Cloudinary upload function.
My code works but I'm having trouble passing form information as Cloudinary parameters.
Here is my current code, which passes the original file name:
router.post('/upload', function (req, res){
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
form.on('end', function(fields, files) {
var temp_path = this.openedFiles[0].path;
var file_name = this.openedFiles[0].name;
cloudinary.uploader.upload(temp_path, function(result) { console.log(result) },
{ public_id: file_name });
})
But I don't want the original file name. Instead of var file_name
I want var image_name
which is provided by the user from the form