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.

Upload formData with S3 pre-signed URL

See original GitHub issue

Hello, first, here is the versions I’m using :

 "react": "16.9.0",
 "react-native": "0.61.5",
 "rn-fetch-blob": "^0.12.0"

I’m trying to upload a file using S3 and pre signed URL. I’m using rn-fetch-blob like this :

RNFetchBlob.fetch('POST', url, {
    'Content-Type' : 'multipart/form-data',
  }, [
    {
      name : name,
      filename: file.fileName,
      data: formData(fields)}
  ]).then((resp) => {
      console.log(resp);
    }).catch((err) => {
      // ...
      console.log("Catch error", err);
    })

where formData is basically a function returning a FormData() object containing all needed informations for S3 key, region, bucket, ....and the urlis the pre signed URL for S3 upload. However, by doing this, I’m getting a black screen, so I just wanted to know, if S3 upload (with pre signed method) was possible to achieve using rn-fetch-blob?

Any ideas, help, is very welcome. Thanks !

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
siriwatknpcommented, Nov 3, 2020
{
  "rn-fetch-blob": 0.12.0,
  "react-native": 0.61.5
}

@matamicen This code works for both Android & iOS

const presignedUrl = "https://xxx.s3.amazonaws.com/abc.mp4?AWSAccessKeyId=xxx&Expires=xxx&Signature=xxx&x-amz-acl=public-read&x-amz-security-token=xxx";

const response = await RNFetchBlob.fetch(
  'PUT',
  presignedUrl,
  {
    'Content-Type': undefined
  },
  RNFetchBlob.wrap(file.path.replace('file://', '')),
)

Note 1. { 'Content-Type': undefined } is needed for iOS (works with Android) 2. file.path.replace('file://', '') is also needed for iOS (works with Android)

1reaction
Balthazar33commented, Jun 16, 2021

Hi @manilbajracharya @siriwatknp This is how I’ve implemented it:

s3.getSignedUrl('putObject', {
                    Key: 'responses/' + filename,
                    Body: file,
                    Bucket: AWScreds.bucketLanding,
                    Tagging: "tag"
                  }, (err, url) => {
                    if (url) {
                     
                      console.log("SIGNED URL", url);
                      // ========================Upload file========================
                      RNFetchBlob.fetch('PUT', url,
                        {
                          'Content-Type': undefined
                        },
                        RNFetchBlob.wrap(filePath))
                        .then((res) => {
                          console.log("Uploaded", res.text())
                        })
                        .catch((err) => {
                          console.log("Err", err);
                        });
                      // ========================Upload file========================
                    }

This throws no error in the console, but when I paste the signed url in the browser, this is what I see:

<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>

RN version: 0.63.4 OS: Android Library version: ^0.12.0

Could you please let me know where I might be making a mistake? Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload files to AWS S3 using pre-signed POST data ... - Webiny
Start your serverless journey by learning how to upload files directly to S3 using pre-signed POST data and a simple Lambda function.
Read more >
Uploading formData file from client to S3 using ...
I've tried: Both getPresignedUrl & createPresignedPost to generate the url; Both PUT & POST requests; Setting headers ( Content ...
Read more >
Multipart uploads with S3 pre-signed URLs | Altostra
Upload the object's parts. Complete multipart upload. For that to work with pre-signed URLs, we should add one more stage: generating pre-signed ...
Read more >
S3 direct file upload using presigned URL from React and Rails
In this post we'll discuss how to upload a file directly on Amazon S3 using presigned URL from React and Ruby on Rails...
Read more >
AWS S3 Presigned Post upload in JavaScript with FormData
result of presigned post Aws::S3::Bucket.presigned_post API call. type TokenT = {. url: ?string,. fields: Map<string, any>,. };. // file is a web api...
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