react-s3-uploader
Advanced tools
Comparing version 0.1.1 to 1.0.0
{ | ||
"name": "react-s3-uploader", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "React component that renders an <input type=\"file\"/> and automatically uploads to an S3 bucket", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,1 +6,46 @@ react-s3-uploader | ||
Install | ||
----------- | ||
$ npm install react-s3-uploader | ||
From Browser | ||
------------ | ||
var ReactS3Uploader = require('react-s3-uploader'); | ||
... | ||
<ReactS3Uploader | ||
signingUrl="/s3/sign" | ||
accept="image/*" | ||
onProgress={this.onUploadProgress} | ||
onError={this.onUploadError} | ||
onFinish={this.onUploadFinish}/> | ||
The above example shows all supported `props`. | ||
This expects a request to `/s3/sign` to return JSON with a `signedUrl` property that can be used | ||
to PUT the file in S3. | ||
The resulting DOM is essentially: | ||
<input type="file" onChange={this.uploadFile} /> | ||
When a file is chosen, it will immediately be uploaded to S3. You can listen for progress (and | ||
create a status bar, for example) by providing an `onProgress` function to the component. | ||
Server-Side | ||
----------- | ||
You can use the Express router that is bundled with this module to answer calls to `/s3/sign` | ||
app.use('/s3', require('react-s3-uploader/s3router')({ | ||
bucket: "MyS3Bucket" | ||
})); | ||
This also provides another endpoint: `GET /s3/img/(.*)`. This will create a temporary URL | ||
that provides access to the uploaded file (which are uploaded privately at the moment). The | ||
request is then redirected to the URL, so that the image is served to the client. | ||
You must provide environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY` to use the server route. |
@@ -10,3 +10,3 @@ | ||
var AWS_ACCESS_KEY = options.accessKey || process.env.AWS_ACCESS_KEY, | ||
var AWS_ACCESS_KEY_ID = options.accessKey || process.env.AWS_ACCESS_KEY_ID, | ||
AWS_SECRET_KEY = options.secretKey || process.env.AWS_SECRET_KEY, | ||
@@ -17,7 +17,7 @@ S3_BUCKET = options.bucket, | ||
if (!AWS_ACCESS_KEY || !AWS_SECRET_KEY || !S3_BUCKET) { | ||
throw new Error("AWS_ACCESS_KEY, AWS_SECRET_KEY, and S3_BUCKET must be available."); | ||
if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_KEY || !S3_BUCKET) { | ||
throw new Error("AWS_ACCESS_KEY_ID, AWS_SECRET_KEY, and S3_BUCKET must be available."); | ||
} | ||
aws.config.update({accessKeyId: AWS_ACCESS_KEY , secretAccessKey: AWS_SECRET_KEY }); | ||
aws.config.update({accessKeyId: AWS_ACCESS_KEY_ID , secretAccessKey: AWS_SECRET_KEY }); | ||
@@ -75,2 +75,2 @@ var router = express.Router(); | ||
module.exports = S3Router; | ||
module.exports = S3Router; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10648
202
1
51