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.

How to upload to S3 bucket?

See original GitHub issue

Hi, Is there a way to upload to S3 bucket?

I tried it like this and got the following error:

const options = {
    url: 'https://s3.amazonaws.com/mybucketname',
    method: 'POST',
    path: uri, // /Users/user/Library/.../5D94544E-E33B-475E-BB3F-5BFA72E15A63.jpg
    type: 'multipart',
    headers: {
    },
    field: 'uploaded_media',
    region: "us-east-1",
    accessKey: 'myaccesskey',
    secretKey: "mysecretkey",
    // Below are options only supported on Android
    notification: {
      enabled: true
    }
  };

  Upload.startUpload(options).then((uploadId) => {
    console.log('Upload started');
    Upload.addListener('progress', uploadId, (data) => {
      console.log(`Progress: ${data.progress}%`)
    });
    Upload.addListener('error', uploadId, (data) => {
      console.log(`Error: ${data.error}%`)
    });
    Upload.addListener('cancelled', uploadId, (data) => {
      console.log(`Cancelled!`)
    });
    Upload.addListener('completed', uploadId, (data) => {
      console.log('Completed!', data)
    })
  }).catch((err) => {
    console.log('Upload error!', err)
  });

and i got this error:

{id: "9", responseCode: 400, responseBody: "<?xml version="1.0" encoding="UTF-8"?>↵<Error><Cod…lyaNSBlMomTWSgYgOloDwFtOReU01RA=</HostId></Error>"}
id
:
"9"
responseBody
:
"<?xml version="1.0" encoding="UTF-8"?>↵<Error><Code>MaxPostPreDataLengthExceeded</Code><Message>Your POST request fields preceeding the upload file was too large.</Message><MaxPostPreDataLengthBytes>20480</MaxPostPreDataLengthBytes><RequestId>83B08A26C8A163F4</RequestId><HostId>EKI1mI93HBz1uQIdo+gk4aTATLawDTb/hUYGvR/JNtDilyaNSBlMomTWSgYgOloDwFtOReU01RA=</HostId></Error>"
responseCode
:
400

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
brianephraimcommented, May 29, 2019
       import Upload from 'react-native-background-upload';
       import { S3Policy } from 'common/react-native-aws3/S3Policy'; // https://github.com/benjreinhart/react-native-aws3

        const fileInfo = await Upload.getFileInfo(videoPath);
        const options = {
          type: 'multipart',
          method: 'POST',
          headers: {
            'content-type': fileInfo.mimeType, // server requires a content-type header
            'content-length': `${fileInfo.size}`,
          },
          url: 'https://asdf.s3.amazonaws.com',
          field: 'file',
          path: videoPath,
          parameters: {
            ...S3Policy.generate({
              bucket: 'qwer',
              region: 'us-east-1',
              accessKey: 'XX',
              secretKey: 'YY',
              successActionStatus: 201,
              key: `uploads/${fileInfo.name}`,
              date: new Date(),
              contentType: fileInfo.mimeType,
            }),
          },
        };

        const uploadId = await Upload.startUpload(options);
``
0reactions
otuswebcommented, Oct 1, 2020

If like me you are looking to simply upload to a public bucket, here is the code I used that worked:

const options = {
            url: 'https://s3-eu-west-1.amazonaws.com/xxxxxxxx/',
            path: result.fileCopyUri,
            method: 'POST',
            type: 'multipart',
            field: 'file',
            maxRetries: 2, // set retry count (Android only). Default 2
            headers: {
              'content-type': 'application/octet-stream', // Customize content-type
            },
            parameters:{
              key: result.name
            }
          };

          Upload.startUpload(options)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uploading objects - Amazon Simple Storage Service
This procedure explains how to upload objects and folders to an S3 bucket using the console. When you upload an object, the object...
Read more >
How To Upload File to S3 with the AWS CLI
Learn how to use the AWS CLI tool to upload, download, and synchronize files and folders between local locations and AWS S3 buckets....
Read more >
How to Upload Files to AWS S3 with the AWS CLI
When you log in to the AWS portal, navigate to the S3 bucket, choose your required bucket, and download or upload the files....
Read more >
How to upload files to AWS S3 - YouTube
Amazon Simple Storage Service (Amazon S3 ) is object storage with a simple web service interface to store and retrieve any amount of...
Read more >
AWS S3 Tutorial - How to Create S3 Bucket and Upload Files?
This AWS S3 tutorial explain how to create S3 bucket and upload files. It is a hands-on video, so be ready with your...
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