I’m building an admin UI using Express + Node.JS. I’m handing all the backendless request using Backendless JS API on Node server and it works perfectly fine. I have one requirement where i have to upload images, when i try to post the file using the below code, i get an error “Upload File not supported with NodeJS”. Can you please advice how to perform this task on Node.JS server?
Backendless.Files.upload( files, "my-folder", callback );
Hi Arasan,
You can do uploading of files using our REST SDK
In my example, I use npm module ‘request’ for posting the file to the Backendless Server.
var https = require('https');
var request = require('request');
var fs = require('fs');
var options = {
url: 'https://api.backendless.com/v1/files/web/896.jpg',
headers: {
'application-id': '******************',
'secret-key': '****************',
'Content-Type': 'multipart/form-data',
'application-type': 'REST'
},
formData: {
my_file: fs.createReadStream(__dirname + '/896.jpg')
}
};
request.post(options, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
Regards, Ilya