-
Notifications
You must be signed in to change notification settings - Fork 637
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
When upload large file using stream by Upload module on webApp, httpUploadProgress event object property 'total' always undefined.
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v18.13.0
Reproduction Steps
- setup Node.js project
- install @aws-sdk/client-s3 and @aws-sdk/lib-storage
- prepare upload file (larger than 5 MB)
- run the following program
- may see ev.total always undefined
const fs = require("fs");
const stream = require("stream");
const S3Client = require("@aws-sdk/client-s3").S3Client;
const Upload = require("@aws-sdk/lib-storage").Upload;
const s3 = new S3Client({
// your s3 settings
});
async function main() {
// Use a file larger than 5MB.
const fileStream = fs.createReadStream("/path/to/your/over5mb/file.dat");
const passThrough = new stream.PassThrough();
// Pipe PassThrough to remove fileStream.path
// to emulate browser file upload.
fileStream.pipe(passThrough);
const upload = new Upload({
client: s3,
params: {
Bucket: // your Bucket,
Key: // your Key,
Body: passThrough,
},
});
upload.on("httpUploadProgress", function (ev) {
// ev.total always undefined
console.log(ev);
});
await upload.done();
}
main();By debugging the code, no assignment for this.totalBytes( references of 'total') anywhere excepted in constructor and function for one chunk
Observed Behavior
httpUploadProgress event object property 'total' always undefined.
(In sample code, console output of ev.total is undefined to the end )
Expected Behavior
finally set the correct total file size
(In sample code, final console output of ev.total is the correct total file size)
Possible Solution
No response
Additional Information/Context
aws-sdk v2 was recalculating this.totalBytes on readable event
https://github.com/aws/aws-sdk-js/blob/b168eaab7aa04f8fc300b38bf67f9c26bf02c28a/lib/s3/managed_upload.js#L188