Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(util-body-length-node): fs.ReadStream with path of Buffer type #3384

Merged
merged 4 commits into from
Mar 8, 2022

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Feb 28, 2022

Issue

Fixes: #3383

Description

Supports computation of body length when fs.ReadStream is created with path of type Buffer.

Testing

Verified that object is successfully uploaded

PutObject without Checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { createReadStream } from "fs";

const region = "us-west-2";
const client = new S3({ region });

// File created with command "(for i in {1..1000}; do echo $i "hello world"; done) > hello-world.txt"
const fileName = "hello-world.txt";
const readableStream = createReadStream(Buffer.from(fileName));

const Bucket = "aws-sdk-js-trivikr";
const Key = fileName;
const Body = readableStream;

try {
  await client.putObject({ Bucket, Key, Body });
} catch (error) {
  console.log({ error });
}
PutObject with Checksum
import { S3 } from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import { createReadStream } from "fs";

const region = "us-west-2";
const client = new S3({ region });

// File created with command "(for i in {1..1000}; do echo $i "hello world"; done) > hello-world.txt"
const fileName = "hello-world.txt";
const readableStream = createReadStream(Buffer.from(fileName));

const Bucket = "aws-sdk-js-trivikr";
const Key = fileName;
const Body = readableStream;
const ChecksumAlgorithm = "CRC32";

try {
  await client.putObject({ Bucket, Key, Body, ChecksumAlgorithm });
} catch (error) {
  console.log({ error });
}

Additional context

This PR will be made ready after #3381 is merged. Ready!


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr force-pushed the fix-util-body-length-node-path-buffer branch from 5aebe0d to 5d85cb6 Compare March 8, 2022 17:09
@trivikr trivikr marked this pull request as ready for review March 8, 2022 17:09
@trivikr trivikr requested a review from a team as a code owner March 8, 2022 17:09
@trivikr trivikr merged commit d220242 into aws:main Mar 8, 2022
@trivikr trivikr deleted the fix-util-body-length-node-path-buffer branch March 8, 2022 20:43
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 throws NotImplemented error if body from fs.createReadStream is passed a buffer
2 participants