question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[S3 Client] Errors if the `Body` of `PutObjectCommand` is a `Readable` type.

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
ffxsamcommented, May 14, 2021

Just in case anyone needs a clear answer: putObject can’t write a stream to S3, you have to use the Upload class in @aws-sdk/lib-storage.

8reactions
AllanZhengYPcommented, May 13, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found