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(lib-storage): fix fs error on browsers when using lib-storage upload #2165

Merged
merged 1 commit into from
Mar 22, 2021
Merged

fix(lib-storage): fix fs error on browsers when using lib-storage upload #2165

merged 1 commit into from
Mar 22, 2021

Conversation

ajredniwja
Copy link
Contributor

@ajredniwja ajredniwja commented Mar 22, 2021

Issue

Issue number, if available, prefixed with "#"
fixes: #2136, #2156

Description

What does this implement/fix? Explain your changes.

Testing

How was this change tested?
Ran manual tests on browser and in node

Browser code:

(async () => {
    const creds = fromCognitoIdentityPool({
        client: new CognitoIdentityClient({ region }),
        identityPoolId: idPool,
    });
    const client = new S3Client({
        region,
        credentials: creds
    });



    const Key = `${Date.now()}-new-key`;
    let upload = new Upload({
        client,
        tags: [{
            Key: "my-tag-key",
            Value: "my-tag-value"
        }],
        params: { Key, Bucket,
            Body: "hello world!"
        }
    }); 

    upload.on("httpUploadProgress", (progress ) => {
        console.log(progress);
    });

    const uploadResult = await upload.done();
    
    console.log(uploadResult);

})();

Node:

(async () => {
    const fs = require("fs");
    const { S3  } = require("@aws-sdk/client-s3");
    const { Upload } = require("@aws-sdk/lib-storage")
    const client = new S3({
      region: "us-west-2",
    });
    try {
      const upload = new Upload({
        client,
        params: {
          Bucket: "bucket",
          Key: "docket",
          Body: fs.createReadStream("/path/to/file")
        }
      });

      upload.on("httpUploadProgress", (progress ) => {
        console.log(progress);
      });

      const result = await upload.done();
      console.log(result)
    } catch(e) {
      console.log(e);
    }
  })();

Additional context

Add any other context about the PR here.

cc @alexforsyth


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

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: 45999f0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@alexforsyth alexforsyth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit due to naming, LGTM

@ajredniwja ajredniwja changed the title Fix browser dependency for fs fix(lib-storage): fix fs error on browsers when using lib-storage upload Mar 22, 2021
@ajredniwja ajredniwja merged commit 5d9bc5f into aws:main Mar 22, 2021
@ajredniwja ajredniwja deleted the fsFix branch March 22, 2021 21:02
@github-actions
Copy link

github-actions bot commented Apr 6, 2021

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 Apr 6, 2021
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.

Module not found: Can't resolve 'fs' in 'node_modules/@aws-sdk/lib-storage/dist/es'
3 participants