react-s3-uploader
Advanced tools
Comparing version 3.0.3 to 3.1.0
{ | ||
"name": "react-s3-uploader", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "React component that renders a file input and automatically uploads to an S3 bucket", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
119
README.md
@@ -8,23 +8,25 @@ react-s3-uploader | ||
----------- | ||
$ npm install react-s3-uploader | ||
```bash | ||
$ npm install react-s3-uploader | ||
``` | ||
From Browser | ||
------------ | ||
var ReactS3Uploader = require('react-s3-uploader'); | ||
```jsx | ||
var ReactS3Uploader = require('react-s3-uploader'); | ||
... | ||
... | ||
<ReactS3Uploader | ||
signingUrl="/s3/sign" | ||
accept="image/*" | ||
onProgress={this.onUploadProgress} | ||
onError={this.onUploadError} | ||
onFinish={this.onUploadFinish} | ||
signingUrlHeaders={{ additional: headers }} | ||
signingUrlQueryParams={{ additional: query-params }} | ||
uploadRequestHeaders={{ 'x-amz-acl': 'public-read' }} | ||
contentDisposition="auto" | ||
server="http://cross-origin-server.com" /> | ||
<ReactS3Uploader | ||
signingUrl="/s3/sign" | ||
accept="image/*" | ||
onProgress={this.onUploadProgress} | ||
onError={this.onUploadError} | ||
onFinish={this.onUploadFinish} | ||
signingUrlHeaders={{ additional: headers }} | ||
signingUrlQueryParams={{ additional: query-params }} | ||
uploadRequestHeaders={{ 'x-amz-acl': 'public-read' }} | ||
contentDisposition="auto" | ||
server="http://cross-origin-server.com" /> | ||
``` | ||
@@ -47,3 +49,5 @@ The above example shows all supported `props`. For `uploadRequestHeaders`, the default ACL is shown. | ||
<input type="file" onChange={this.uploadFile} /> | ||
```jsx | ||
<input type="file" onChange={this.uploadFile} /> | ||
``` | ||
@@ -58,9 +62,11 @@ When a file is chosen, it will immediately be uploaded to S3. You can listen for progress (and | ||
app.use('/s3', require('react-s3-uploader/s3router')({ | ||
bucket: "MyS3Bucket", | ||
region: 'us-east-1', //optional | ||
signatureVersion: 'v4', //optional (use for some amazon regions: frankfurt and others) | ||
headers: {'Access-Control-Allow-Origin': '*'}, // optional | ||
ACL: 'private' // this is default | ||
})); | ||
```js | ||
app.use('/s3', require('react-s3-uploader/s3router')({ | ||
bucket: "MyS3Bucket", | ||
region: 'us-east-1', //optional | ||
signatureVersion: 'v4', //optional (use for some amazon regions: frankfurt and others) | ||
headers: {'Access-Control-Allow-Origin': '*'}, // optional | ||
ACL: 'private' // this is default | ||
})); | ||
``` | ||
@@ -81,40 +87,45 @@ This also provides another endpoint: `GET /s3/img/(.*)` and `GET /s3/uploads/(.*)`. This will create a temporary URL | ||
import boto | ||
import mimetypes | ||
import json | ||
```python | ||
import boto | ||
import mimetypes | ||
import json | ||
... | ||
conn = boto.connect_s3('AWS_KEY', 'AWS_SECRET') | ||
... | ||
def sign_s3_upload(request): | ||
object_name = request.GET['objectName'] | ||
content_type = mimetypes.guess_type(object_name)[0] | ||
conn = boto.connect_s3('AWS_KEY', 'AWS_SECRET') | ||
signed_url = conn.generate_url( | ||
300, | ||
"PUT", | ||
'BUCKET_NAME', | ||
'FOLDER_NAME' + object_name, | ||
headers = {'Content-Type': content_type, 'x-amz-acl':'public-read'}) | ||
def sign_s3_upload(request): | ||
object_name = request.GET['objectName'] | ||
content_type = mimetypes.guess_type(object_name)[0] | ||
return HttpResponse(json.dumps({'signedUrl': signed_url})) | ||
signed_url = conn.generate_url( | ||
300, | ||
"PUT", | ||
'BUCKET_NAME', | ||
'FOLDER_NAME' + object_name, | ||
headers = {'Content-Type': content_type, 'x-amz-acl':'public-read'}) | ||
return HttpResponse(json.dumps({'signedUrl': signed_url})) | ||
``` | ||
#### Ruby on Rails, assuming FOG usage | ||
# Usual fog config, set as an initializer | ||
FOG = Fog::Storage.new({ | ||
:provider => 'AWS', | ||
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'], | ||
:aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] | ||
}) | ||
```ruby | ||
# Usual fog config, set as an initializer | ||
storage = Fog::Storage.new( | ||
provider: 'AWS', | ||
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'], | ||
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] | ||
) | ||
# In the controller | ||
options = {path_style: true} | ||
headers = {"Content-Type" => params[:contentType], "x-amz-acl" => "public-read"} | ||
# In the controller | ||
options = {path_style: true} | ||
headers = {"Content-Type" => params[:contentType], "x-amz-acl" => "public-read"} | ||
@url = FOG.put_object_url(ENV['S3_BUCKET_NAME'], "user_uploads/#{params[:objectName]}", 15.minutes.from_now.to_time.to_i, headers, options) | ||
@url = storage.put_object_url(ENV['S3_BUCKET_NAME'], "user_uploads/#{params[:objectName]}", 15.minutes.from_now.to_time.to_i, headers, options) | ||
respond_to do |format| | ||
format.json { render json: {signedUrl: @url} } | ||
end | ||
respond_to do |format| | ||
format.json { render json: {signedUrl: @url} } | ||
end | ||
``` | ||
@@ -130,2 +141,6 @@ | ||
##### 3.1.0 | ||
* Replace unsafe characters (per AWS docs) with underscores [#69] | ||
##### 3.0.3 | ||
@@ -132,0 +147,0 @@ |
@@ -66,3 +66,3 @@ /** | ||
S3Upload.prototype.executeOnSignedUrl = function(file, callback) { | ||
var normalizedFileName = unorm.nfc(file.name.replace(/\s+/g, "_")); | ||
var normalizedFileName = unorm.nfc(file.name.replace(/[!\^`><{}\[\]()*#%'"~|&@:;$=+?\s\\\/\x00-\x1F\x7f]+/ig, '_')); | ||
var fileName = latinize(normalizedFileName); | ||
@@ -138,3 +138,3 @@ var queryString = '?objectName=' + fileName + '&contentType=' + encodeURIComponent(file.type); | ||
} | ||
var normalizedFileName = unorm.nfc(file.name.replace(/\s+/g, "_")); | ||
var normalizedFileName = unorm.nfc(file.name.replace(/[!\^`><{}\[\]()*#%'"~|&@:;$=+?\s\\\/\x00-\x1F\x7f]+/ig, '_')); | ||
var fileName = latinize(normalizedFileName); | ||
@@ -141,0 +141,0 @@ xhr.setRequestHeader('Content-Disposition', disposition + '; filename=' + fileName); |
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
18493
184