[S3 Client] Errors if the `Body` of `PutObjectCommand` is a `Readable` type.
See original GitHub issueDescribe the bug
I got this error when I set the Body
to a Readable
type.
(node:88634) UnhandledPromiseRejectionWarning: NotImplemented: A header you provided implies functionality that is not implemented
SDK version number 3.13.1
To Reproduce (observed behavior)
import { fromIni } from '@aws-sdk/credential-provider-ini'
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import https from 'https'
import { Readable } from 'stream'
import awsConfig from './aws-exports'
const s3Client = new S3Client({
credentials: fromIni({ profile: 'default' }),
region: 'ap-northeast-1',
})
async function getFileFromUrl(url: string): Promise<Readable> {
return new Promise((resolve) => {
https.get(url, (response) => {
resolve(response)
})
})
}
async function upload(file: Readable) {
const uploadCommand = new PutObjectCommand({
Bucket: awsConfig.aws_user_files_s3_bucket,
Key: 'test.jpg',
Body: file,
ACL: 'public-read',
})
await s3Client.send(uploadCommand)
}
async function migrate() {
const file = await getFileFromUrl(
'https://example.com/logo.png'
)
await upload(file)
console.log('done')
}
migrate()
I could confirm that it’s ok if I change the Body
to a string, so I’m sure I have the right permission to put an object to the bucket.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
[S3 Client] Errors if the Body of PutObjectCommand is ... - GitHub
Describe the bug I got this error when I set the Body to a Readable type. (node:88634) UnhandledPromiseRejectionWarning: NotImplemented: A ...
Read more >PutObjectCommand | S3 Client - AWS SDK for JavaScript v3
Amazon S3 is a distributed system. If it receives multiple write requests for the same object simultaneously, it overwrites all but the last...
Read more >AWS s3 V3 Javascript SDK stream file from bucket ...
Body from the GetObjectCommand is a readable stream ... s3Client.send(command) returns a type GetObjectCommandOutput . ... if (!data.Body)
Read more >Upload an object to an Amazon S3 bucket using an Amazon ...
Key: "OBJECT_NAME", // Content of the new object. Body: "BODY", }; // Create and upload the object to the S3 bucket. export const...
Read more >Troubleshoot IAM-related Access Denied errors in Amazon S3
However, when they try to upload an object, they g. ... permission to add objects to my Amazon S3 bucket is getting Access...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just in case anyone needs a clear answer:
putObject
can’t write a stream to S3, you have to use theUpload
class in@aws-sdk/lib-storage
.Hi @fabis94 @yaquawa @guanzo, The error is indeed caused by stream length remaining unknown. We need to improve the error message and the documentation. As it’s pointed out in the Upgrading Guide, the similar functionality as
s3.upload()
in v2 is now moved to@aws-sdk/lib-storage
package.