React Native Aws3

Pure JavaScript React Native library for uploading to AWS S3
Alternatives To React Native Aws3
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Transfer.sh14,038213 days ago24May 15, 202236mitGo
Easy and fast file sharing from the command-line.
Shrine3,072255454 days ago53June 14, 20219mitRuby
File Attachment toolkit for Ruby applications
Evaporatejs1,76226124 months ago51October 08, 201791JavaScript
Javascript library for browser to S3 multipart resumable uploads
S3 Uploads1,7564392 days ago19July 30, 2021178PHP
The WordPress Plugin to Store Uploads on Amazon S3
S4cmd1,249
75 months ago5August 13, 2018107apache-2.0Python
Super S3 command line tool
React S3 Uploader776118342 years ago59November 04, 202052mitJavaScript
React component that renders an <input type="file"/> and automatically uploads to an S3 bucket
S3_direct_upload648
5 years ago114mitRuby
Direct Upload to Amazon S3 With CORS
Django S3direct602761a year ago78June 17, 202233mitPython
Directly upload files to S3 compatible services with Django.
S3 Plugin Webpack47712559a year ago37November 04, 202015mitJavaScript
Uploads files to s3 after complete
Gulp Awspublish3981,5301995 months ago57March 04, 202221mitJavaScript
gulp plugin to publish files to amazon s3
Alternatives To React Native Aws3
Select To Compare


Alternative Project Comparisons
Readme

React Native AWS3

React Native AWS3 is a module for uploading files to S3. Unlike other libraries out there, there are no native dependencies.

npm install --save react-native-aws3

build status npm version npm downloads

Note on S3 user permissions

The user associated with the accessKey and secretKey you use must have the appropriate permissions assigned to them. My user's IAM policy looks like:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1458840156000",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:GetObjectVersion",
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:PutObjectVersionAcl"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket/uploads/*"
            ]
        }
    ]
}

Example

import { RNS3 } from 'react-native-aws3';

const file = {
  // `uri` can also be a file system path (i.e. file://)
  uri: "assets-library://asset/asset.PNG?id=655DBE66-8008-459C-9358-914E1FB532DD&ext=PNG",
  name: "image.png",
  type: "image/png"
}

const options = {
  keyPrefix: "uploads/",
  bucket: "your-bucket",
  region: "us-east-1",
  accessKey: "your-access-key",
  secretKey: "your-secret-key",
  successActionStatus: 201
}

RNS3.put(file, options).then(response => {
  if (response.status !== 201)
    throw new Error("Failed to upload image to S3");
  console.log(response.body);
  /**
   * {
   *   postResponse: {
   *     bucket: "your-bucket",
   *     etag : "9f620878e06d28774406017480a59fd4",
   *     key: "uploads/image.png",
   *     location: "https://your-bucket.s3.amazonaws.com/uploads%2Fimage.png"
   *   }
   * }
   */
});

Usage

put(file, options)

Upload a file to S3.

Arguments:

  1. file
  • uri required - File system URI, can be assets library path or file:// path
  • name required - The name of the file, will be stored as such in S3
  • type required - The mime type, also used for Content-Type parameter in the S3 post policy
  1. options
  • acl - The Access Control List of this object. Defaults to public-read
  • keyPrefix - Prefix, or path to the file on S3, i.e. uploads/ (note the trailing slash)
  • bucket required - Your S3 bucket
  • region required - The region of your S3 bucket
  • accessKey required - Your S3 AWSAccessKeyId
  • secretKey required - Your S3 AWSSecretKey
  • successActionStatus - HTTP response status if successful, defaults to 201
  • awsUrl - AWS S3 url. Defaults to s3.amazonaws.com
  • timeDelta - Devices time offset from world clock in milliseconds, defaults to 0

Returns an object that wraps an XMLHttpRequest instance and behaves like a promise, with the following additional methods:

  • progress - accepts a callback which will be called with an event representing the progress of the upload. Event object is of shape
    • loaded - amount uploaded
    • total - total amount to upload
    • percent - number between 0 and 1 representing the percent completed
  • abort - aborts the xhr instance

Examples:

RNS3.put(file, options)
  .progress((e) => console.log(e.loaded / e.total)); // or console.log(e.percent)

RNS3.put(file, option)
  .abort();

TODO

  • [ ] Support DeleteObject and (authenticated) GetObject operations.

License

MIT

Popular S3 Projects
Popular Upload Projects
Popular Cloud Computing Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Reactjs
Amazon Web Services
Upload
S3