aws-sdk-js-v3: Angular 19 PutObjectRequest readableStream.getReader is not a function

Checkboxes for prior research

Describe the bug

Hi, I have an Angular application that I recently updated to version 19, and during this migration I also updated aws-sdk/client-s3 to version 3.731.1.

Before the migration the following code worked fine allowing me to upload files to S3. However, now the same code throws the exception TypeError: readableStream.getReader is not a function.

store(filename: string, data: Blob, folder: string): Promise<string> {

  const weakThis = this;

  return new Promise<string>(async (resolve, reject) => {

    try {

      const input: PutObjectRequest = {
        ACL: 'public-read',
        Bucket: this.awsBucket,
        Key: `${folder}/${filename}`,
        Body: data,
      }

      const command = new PutObjectCommand(input);
      const resp = await weakThis.client.send(command);

      if (resp.$metadata.httpStatusCode < 200 || resp.$metadata.httpStatusCode > 299) {
        this.logger.error(`[AwsFileService][store] Error storing file at path ${key}`);
        this.logger.error(`[AwsFileService][store] HTTP Status ${resp.$metadata.httpStatusCode}`);
        reject(resp.$metadata.httpStatusCode);
        return;
      }
      resolve(key);

    } catch (error) {
      debugger;
      console.log(`[AwsFileService][store] Error storing file at path ${key}`);
      this.logger.error(`[AwsFileService][store] Error storing file at path ${key}`);
      console.log(`[AwsFileService][store] ${error}`);
      this.logger.error(`[AwsFileService][store] ${error}`);
      reject(error);
    }
  });
}

Interestingly when I run the Angular application via ng serve this code works as expected. However, when I attempt to build a production copy of the application via ng build, and then run as a standard Node JS application that the issue occurs.

Environment: Node.js: 22.12.0 Angular: 19.1.2 TypeScript: 5.7.3 aws-sdk/client-s3: 3.731.1"

Regression Issue

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

SDK version number

@aws-sdk/client-s3@3.731.1

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

22.12.0

Reproduction Steps

  1. Create a typical Angular 19 application
  2. Install aws-sdk/client-s3
  3. Add code above in description
  4. Test 1: run ng serve
  5. Test 2: run ng build

Observed Behavior

Test 1: File uploads successfully Test 2: Exception is thrown.

Expected Behavior

Test 1: File uploads successfully Test 2: File uploads successfully

Possible Solution

No response

Additional Information/Context

No response

UPDATE

I am thinking the original Test 1 scenario is not valid. Since posting this I changed the version of aws-sdk/client-s3 back to 3.32.0 (last known working version), and now I’m able to replicate the issue regardless of how the app is built. I have switched back to 3.731.1 and am able to replicate the issue both with ng serve and ng build

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

As @aBurmeseDev mentioned, the simplest workaround at the time of comment is to disable checksum computation by setting the following configuration during client creation

  const client = new S3({
    // ... other params
    // ToDo: Remove workaround once https://github.com/aws/aws-sdk-js-v3/issues/6834 is fixed.
    requestChecksumCalculation: "WHEN_REQUIRED",
  });

If the files are not huge, you can convert them to ArrayBuffer too. It’s going to read all bytes into memory though, as per specification.

  // ...
  await client.putObject({
    Bucket: import.meta.env.VITE_AWS_S3_BUCKET_NAME,
    Key: file.name,
    Body: await file.arrayBuffer(),
  });
  // ...

I’ll raise this issue internally with the team on Mon, Jan 27th, and provide an update.

Hi @mike-appvision - thanks for reaching out and for your patience while we look into it.

I noticed you mentioned files were uploaded successfully on Test 1 and failed on Test 2. Could you elaborate on that?

During my attempt to replicate the issue, I was able to reproduce the error in first few uploads and then it started to upload successfully. Here’s my repro for reference: https://github.com/aBurmeseDev/aws-sdk-js-s3-angular

In the meantime, here are a few workarounds we’d like to suggest here:

  • The root cause may be due to the recent change about default data integrity protections with S3. Although it’s not recommended, as a workaround, you can disable checksum by setting client configuration.
  const client = new S3({
  ...
  requestChecksumCalculation: "WHEN_REQUIRED",
  ...
});
  • You can convert input file types into one of these string | Uint8Array | ReadableStreamOptionalType | BlobOptionalType. (ref)
      const fileArrayBuffer = await file.arrayBuffer();  // Convert File to ArrayBuffer

      const command = new PutObjectCommand({
        Bucket: 'Bucket_Name',
        Key: file.name,
        Body: new Uint8Array(fileArrayBuffer),           // Convert ArrayBuffer to Uint8Array
        ContentType: file.type,
      });
  • You may also be able to provide polyfill for the API being used.

Hope it helps! cc: @partheev @wis-dev

For googlers, I experienced this uploading files from Cloudflare Workers. Downgrading and pinning at 3.726.1 was enough.

+1

I have faced this issue and reverted back my package version to 3.617.0 from ^3.617.0.

After debugging, I realized that it’s dues to https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.729.0 minor version update.

As it’s breaking the flow, anyone please provide steps or configuration to avoid this issue.

Thank you for replying! While the latest version of the SDK is still broken, you pointing me to version 3.617.0 has allowed me to patch the issue so my clients can now upload photos. Short term fix for sure, but at least we can upload photos again!

Still occurs for me as of 3.844.0. I did try the workaround below, but it’s not ideal. When do you all think we can see an actual solution to the issue?

https://github.com/aws/aws-sdk-js-v3/issues/6834#issuecomment-2613306914

Facing this error in React 19 (Vite) as well:- TypeError: readableStream.getReader is not a function

@aws-sdk/client-s3 version is 3.749.0

This problem also occurs in React.js + Next.js environment. An error occurs when uploading an image to S3 from the browser.

  • Node.js: 20.18.2
  • React.js: 18.3.1
  • Next.js: 13.5.8

@aws-sdk/client-s3: It worked normally in 3.726.1, but an error occurs in later versions.

  • v3.731.1 ~ 3.744.0
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')
const { fromCognitoIdentityPool } = require('@aws-sdk/credential-provider-cognito-identity')
const { CognitoIdentityClient } = require('@aws-sdk/client-cognito-identity')


const client = new S3Client({
  region,
  credentials: fromCognitoIdentityPool({
    client: new CognitoIdentityClient({ region }),
    identityPoolId: process.env.S3_CLIENT_POOL_ID
  })
})

client.send(new PutObjectCommand({
  Bucket,
  Key,
  Body,
  ContentType,
  Metadata
}))

Error

message: "readableStream.getReader is not a function"
stack: "TypeError: readableStream.getReader is not a function
    at getAwsChunkedEncodingStream (webpack-internal:///../node_modules/@smithy/util-stream/dist-es/getAwsChunkedEncodingStream.browser.js:13:35)
    at eval (webpack-internal:///../node_modules/@aws-sdk/middleware-flexible-checksums/dist-es/flexibleChecksumsMiddleware.js:83:27)

I use Angular 18 and encountered the same issue. As @wis-dev said, 3.726.1 works.