Skip to content

Damaged downloaded file  #7682

@waikiki-bn

Description

@waikiki-bn

Checkboxes for prior research

Describe the bug

Conditions:

  1. Aws-sdk v3.972.0
  2. Archiver v7.0.1
  3. NodeJs v22.14.0

Currently I am working on migration from aws-sdk v2 to aws-sdk v3, but I have problems with downloading files. Files are corrupted after i get them from archive.

User case:

  1. User choose file to download.
  2. My node server with GetObjectCommand requests for data from s3.
  3. Node server stream data from s3 to archive, which is streaming to response.

The main goal is to avoid saving files in memory and use streams.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/client-s3: 3.972.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

22.14.0

Reproduction Steps

So here is example of my code

Download archive logic (error handlers are not included)

const archive = archiver.create('zip-encrypted', archiveOptions as ArchiverOptions)

response.setHeader('Content-Type', 'application/zip')
response.setHeader('Content-Disposition', "attachment; filename*=UTF-8''${suggestedArchiveName}")

const fileObjectReadStream = await s3Client.downloadAttachment({
    Bucket: s3.bucket,
    Key: s3.key
 })

 archive.append(fileObjectReadStream, { name })
 archive.finalize()

S3 downloadAttachment

    const downloadAttachment = async (
      params: GetObjectCommandInput,
      accessToken: string
    ): Promise<Readable> => {
      const command = new GetObjectCommand(params)
      const response = await this.s3Client.send(command)

      if (!response.Body) throw new Error('Missing file data')

      return response.Body as Readable
    }

Observed Behavior

I get the archive, but I cant open the file from the archive. The size of the unzipped file is larger than the size of the original file. (Original is 295.79 KB, unzipped file size is 299 KB)

this happens only with aws-sdk v3 version. I have tried to upload file with aws-sdk v3 and download it as an archive using aws-sdk v2 and everything is fine. The difference in code is to use return s3.upload(input, () => {}).promise() instead of return response Body

I've tried to use transformToWebStream but I've got "The stream has been consumed by other callback"
i've also tried to exlcude archive logic and download to fs as a test, file was damaged too.

Expected Behavior

Same result as in aws-sdk v2

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issuev2-v3-inconsistencyBehavior has changed from v2 to v3, or feature is missing altogether

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions