I'm creating a portal where users can select and upload single files from their PC to S3 on AWS.
Below is my server.js code:
app.post('/submit_doc', function(req, res){
var FileName = req.body.fileName,
Filedescription = req.body.filediscrip,
InputFileName = req.body.inputfile;
AWS.config.region = 'eu-west-1';
var fileStream = fs.createReadStream(FileName);
fileStream.on('error', function (err) {
if (err){
console.log("Error reading file: ", err);
res.send(500);
}
else{
fileStream.on('open', function () {
var s3 = new AWS.S3();
s3.putObject({
Bucket: 'exampleassetcare.com',
Key: 'reports/'+FileName,
Body: fileStream
}, function (err) {
if (err) {
console.log("Error uploading data: ", err);
res.send(500);
}
});
});
I get the error: No such file or directory.
Can someone please help?