diff options
| -rw-r--r-- | s3/gen_policy.py | 21 | ||||
| -rw-r--r-- | s3/upload.html | 19 |
2 files changed, 40 insertions, 0 deletions
diff --git a/s3/gen_policy.py b/s3/gen_policy.py new file mode 100644 index 0000000..4d0180c --- /dev/null +++ b/s3/gen_policy.py @@ -0,0 +1,21 @@ +import base64 +import hmac, hashlib + +POLICY = """{"expiration": "2012-01-01T00:00:00Z", + "conditions": [ + {"bucket": "AWS_BUCKET_NAME"}, + ["starts-with", "$key", "uploads/"], + {"acl": "private"}, + {"success_action_redirect": "/"}, + ["starts-with", "$Content-Type", ""], + ["content-length-range", 0, 1048576] + ] +}""" + +KEY = "AWS_SECRET_KEY" + +policy = base64.b64encode(POLICY) + +sig = base64.b64encode(hmac.new(KEY, policy, hashlib.sha1).digest()) + +print sig diff --git a/s3/upload.html b/s3/upload.html new file mode 100644 index 0000000..b05a599 --- /dev/null +++ b/s3/upload.html @@ -0,0 +1,19 @@ +<!doctype html> +<html> + <head> + <title>S3 POST Upload Form</title> + </head> + <body> + <form action="http://zehimg-test.s3.amazonaws.com/uploads/" method="post" enctype="multipart/form-data"> + <input type="text" name="key" value="testfile.txt" /><br/> + <input type="text" name="acl" value="public-read" /><br/> + <input type="text" name="content-type" value="text/plain" /><br/> + <input type="hidden" name="AWSAccessKeyId" value="AKIAJBSLAMYWUPXGMGFQ" /> + <input type="hidden" name="policy" value="eyJleHBpcmF0aW9uIjogIjIwMTItMDEtMDFUMDA6MDA6MDBaIiwKICAiY29uZGl0aW9ucyI6IFsgCiAgICB7ImJ1Y2tldCI6ICJ6ZWhpbWctdGVzdCJ9LCAKICAgIHsiYWNsIjogInB1YmxpYy1yZWFkIn0sCiAgICB7InN1Y2Nlc3NfYWN0aW9uX3JlZGlyZWN0IjogImh0dHA6Ly9sb2NhbGhvc3QvIn0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRDb250ZW50LVR5cGUiLCAiIl0sCiAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgMTA0ODU3Nl0KICBdCn0=" /> + <input type="hidden" name="signature" value="CKg6xXZP9bofdlQHQX7Vwz7f8E0=" /> + <input name="file" type="file" /> + <input name="submit" value="Upload" type="submit" /> + </form> + </body> + +</html>
\ No newline at end of file |
