Created
October 6, 2012 01:27
-
-
Save philfreo/3843375 to your computer and use it in GitHub Desktop.
Revisions
-
philfreo revised this gist
Dec 18, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import time, os, json, base64, urllib, hmac, sha @app.route('/sign_s3_put/') @login_required -
philfreo revised this gist
Dec 10, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ { "Statement": [{ "Action": [ "s3:GetObject", "s3:PutObject", -
philfreo revised this gist
Dec 10, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import os, json, base64, urllib, hmac, sha @app.route('/sign_s3_put/') @login_required -
philfreo revised this gist
Dec 9, 2012 . 1 changed file with 38 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import json, base64, urllib, hmac, sha @app.route('/sign_s3_put/') @login_required def sign_s3_put(): """ Provide a temporary signature so that users can upload files directly from their browsers to our AWS S3 bucket. The authorization portion is taken from Example 3 on http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html """ # don't give user full control over filename - avoid ability to overwrite files random = base64.urlsafe_b64encode(os.urandom(2)) object_name = random+request.args.get('s3_object_name') object_name = urllib.quote_plus(object_name) # make sure it works for filenames with spaces, etc. mime_type = request.args.get('s3_object_type') expires = int(time.time()+300) # PUT request to S3 must start within X seconds amz_headers = "x-amz-acl:public-read" # set the public read permission on the uploaded file resource = '%s/%s' % (app.config['AWS_EMAIL_ATTACHMENTS_BUCKET_NAME'], object_name) str_to_sign = "PUT\n\n{mime_type}\n{expires}\n{amz_headers}\n/{resource}".format( mime_type=mime_type, expires=expires, amz_headers=amz_headers, resource=resource ) sig = urllib.quote_plus(base64.encodestring(hmac.new(app.config['AWS_EMAIL_ATTACHMENTS_SECRET_ACCESS_KEY'], str_to_sign, sha).digest()).strip()) url = 'https://%s.s3.amazonaws.com/%s' % (app.config['AWS_EMAIL_ATTACHMENTS_BUCKET_NAME'], object_name) return json.dumps({ 'signed_request': '{url}?AWSAccessKeyId={access_key}&Expires={expires}&Signature={sig}'.format( url=url, access_key=app.config['AWS_EMAIL_ATTACHMENTS_ACCESS_KEY_ID'], expires=expires, sig=sig ), 'url': url }) -
philfreo revised this gist
Dec 8, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // https://github.com/elasticsales/s3upload-coffee-javascript var s3upload = new S3Upload({ file_dom_selector: '#files', // an <input type="file"> element s3_sign_put_url: '/sign_s3_put', onProgress: function(percent, message, publicUrl, file) { // Use this for live upload progress bars console.log('Upload progress: ', percent, message); -
philfreo revised this gist
Dec 8, 2012 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ // https://github.com/elasticsales/s3upload-coffee-javascript var s3upload = new S3Upload({ file_dom_selector: '#files', s3_sign_put_url: '/sign_s3_put', onProgress: function(percent, message, publicUrl, file) { // Use this for live upload progress bars console.log('Upload progress: ', percent, message); }, onFinishS3Put: function(public_url, file) { // Get the URL of the uploaded file console.log('Upload finished: ', public_url); }, onError: function(status, file) { console.log('Upload error: ', status); } }); -
philfreo revised this gist
Dec 8, 2012 . 2 changed files with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::bucket_name_here/*" } ] } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ { "Statement": [ { "Action": [ "s3:GetObject", "s3:PutObject", "s3:PutObjectAcl" ], "Effect": "Allow", "Resource": [ "arn:aws:s3:::bucket_name_here/*" ] }] } -
philfreo revised this gist
Dec 5, 2012 . 2 changed files with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <AllowedHeader>Authorization</AllowedHeader> </CORSRule> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>PUT</AllowedMethod> <MaxAgeSeconds>3000</MaxAgeSeconds> <AllowedHeader>Content-Type</AllowedHeader> <AllowedHeader>x-amz-acl</AllowedHeader> <AllowedHeader>origin</AllowedHeader> </CORSRule> </CORSConfiguration> File renamed without changes. -
philfreo created this gist
Oct 6, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ { "Statement": [ { "Sid": "AllowPublicRead", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::your-bucket-name/*" } ] }