After not finding any working solution to this problem for me, I am pasting my Angular Electron app code.
Component
const pipeline = this.syncService.uploadSong(localPath, filename);
pipeline.on('close', (data) => {
// upload finished
})
pipeline.on('error', (err) => {
console.error(err.toString());
})
And the service is :
uploadSong(localPath: string, filename: string) {
const {writeStream, promise} = this.uploadStream(filename);
const readStream = fs.createReadStream(localPath);
return readStream.pipe(writeStream);
}
uploadStream(filename: string) {
const stream = require('stream'); // "stream": "0.0.2",
const pass = new stream.PassThrough();
const params = {
Body: pass,
Bucket: this.s3Bucket,
Key: filename,
};
const options = {partSize: 5 * 1024 * 1024, queueSize: 6};
return {
writeStream: pass,
promise: this.s3.upload(params,options).promise() // ERROR Because the Body
};
}
The localPath is checked before with fs.stats, so the error is not because the file is not there. In fact I am able to use it on a s3.putObject, before realising the size of the uploads.