-
Notifications
You must be signed in to change notification settings - Fork 658
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
Conditions:
- Aws-sdk v3.972.0
- Archiver v7.0.1
- 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:
- User choose file to download.
- My node server with GetObjectCommand requests for data from s3.
- 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