I need to upload a file from my Electron app to a web application (node.js + Express), by first gathering meta-data along with the selected file (from a HTML form in the Electron app) and issue a POST request to the web application. The web application processes this request by saving the file to a pre-configured location on the disk and the meta-data and the path of the saved file to a database. Referring to SO, I decided to use request and form-data to compose the request with the form data and issue a POST request, using code looking like this:
var fs = require('fs');
var request = require('request');
var FormData = require('form-data');
let formData = {
'name': imageName,
'mediaType': mediaType,
'extension': extension,
'resolution.x': resolutionX,
'resolution.y': resolutionY,
'url': url,
'file': fs.createReadStream(absFilePath)
};
request.post({
url: 'http://localhost:8080/images',
formData: formData
}, function(err, response, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Server responded with:', response);
});
In the Electron app, the console displays Server responded with: [IncomingMessage]
and the response status code is 500. It is quite confusing and I am unable to grasp the examples in the Github pages for the two projects. How do I issue a POST request to achieve the above described goals?