Skip to content

The 'total' property is always undefined when uploading files larger than 5MBΒ #4413

@ti2sugiyama

Description

@ti2sugiyama

Checkboxes for prior research

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

  1. setup Node.js project
  2. install @aws-sdk/client-s3 and @aws-sdk/lib-storage
  3. prepare upload file (larger than 5 MB)
  4. run the following program
  5. 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

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issuequeuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions