react-s3-uploader
Advanced tools
Comparing version 4.5.0 to 4.5.1
##### 4.5.1 | ||
* Add `inputRef` prop [#153] | ||
##### 4.5.0 | ||
@@ -3,0 +7,0 @@ |
{ | ||
"name": "react-s3-uploader", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "React component that renders a file input and automatically uploads to an S3 bucket", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,3 +33,4 @@ "use strict"; | ||
scrubFilename: PropTypes.func, | ||
s3path: PropTypes.string | ||
s3path: PropTypes.string, | ||
inputRef: PropTypes.func | ||
}, | ||
@@ -95,3 +96,10 @@ | ||
getInputProps: function() { | ||
var temporaryProps = objectAssign({}, this.props, {type: 'file', onChange: this.uploadFile}); | ||
// declare ref beforehand and filter out | ||
// `inputRef` by `ReactS3Uploader.propTypes` | ||
var additional = { | ||
type: 'file', | ||
onChange: this.uploadFile, | ||
ref: this.props.inputRef | ||
}; | ||
var temporaryProps = objectAssign({}, this.props, additional); | ||
var inputProps = {}; | ||
@@ -98,0 +106,0 @@ |
@@ -185,5 +185,52 @@ react-s3-uploader | ||
#### [Micro](https://github.com/zeit/micro) | ||
```javascript | ||
const aws = require('aws-sdk') | ||
const uuidv4 = require('uuid/v4') | ||
const { createError } = require('micro') | ||
const options = { | ||
bucket: 'S3_BUCKET_NAME', | ||
region: 'S3_REGION', | ||
signatureVersion: 'v4', | ||
ACL: 'public-read' | ||
} | ||
const s3 = new aws.S3(options) | ||
module.exports = (req, res) => { | ||
const originalFilename = req.query.objectName | ||
// custom filename using random uuid + file extension | ||
const fileExtension = originalFilename.split('.').pop() | ||
const filename = `${uuidv4()}.${fileExtension}` | ||
const params = { | ||
Bucket: options.bucket, | ||
Key: filename, | ||
Expires: 60, | ||
ContentType: req.query.contentType, | ||
ACL: options.ACL | ||
} | ||
const signedUrl = s3.getSignedUrl('putObject', params) | ||
if (signedUrl) { | ||
// you may also simply return the signed url, i.e. `return { signedUrl }` | ||
return { | ||
signedUrl, | ||
filename, | ||
originalFilename, | ||
publicUrl: signedUrl.split('?').shift() | ||
} | ||
} else { | ||
throw createError(500, 'Cannot create S3 signed URL') | ||
} | ||
} | ||
``` | ||
##### Other Servers | ||
If you do some work on another server, and would love to contribute documentation, please send us a PR! |
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
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
26697
385
236