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
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:
Example
; 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;
Usage
put(file, options)
Upload a file to S3.
Arguments:
file
uri
required - File system URI, can be assets library path orfile://
pathname
required - The name of the file, will be stored as such in S3type
required - The mime type, also used forContent-Type
parameter in the S3 post policy
options
acl
- The Access Control List of this object. Defaults topublic-read
keyPrefix
- Prefix, or path to the file on S3, i.e.uploads/
(note the trailing slash)bucket
required - Your S3 bucketregion
required - The region of your S3 bucketaccessKey
required - Your S3AWSAccessKeyId
secretKey
required - Your S3AWSSecretKey
successActionStatus
- HTTP response status if successful, defaults to 201awsUrl
- AWS S3 url. Defaults tos3.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 shapeloaded
- amount uploadedtotal
- total amount to uploadpercent
- number between 0 and 1 representing the percent completed
abort
- aborts the xhr instance
Examples:
RNS3 ; // or console.log(e.percent) RNS3 ;
TODO
- Support
DeleteObject
and (authenticated)GetObject
operations.