【发布时间】:2020-10-01 11:18:05
【问题描述】:
在没有为我找到解决此问题的任何有效解决方案后,我正在粘贴我的 Angular Electron 应用代码。
组件
const pipeline = this.syncService.uploadSong(localPath, filename);
pipeline.on('close', (data) => {
// upload finished
})
pipeline.on('error', (err) => {
console.error(err.toString());
})
服务是:
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
};
}
之前用fs.stats检查过localPath,所以错误不是因为文件不存在。事实上,在意识到上传的大小之前,我可以在 s3.putObject 上使用它。
【问题讨论】: