Created
August 17, 2013 07:13
-
-
Save cameronjacobson/6255689 to your computer and use it in GitHub Desktop.
bare-bones Browser-based S3 POST
This file contains 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 characters
<?php | |
if(isset($_GET['success'])){ | |
echo 'done'; | |
exit; | |
} | |
$policy = base64_encode(str_replace(array("\r","\n"),"",'{ "expiration": "2023-01-01T12:00:00.000Z", "conditions": [ | |
{"acl": "public-read" }, | |
{"bucket": "MYBUCKET" }, | |
["starts-with", "$key", "UUID/"], | |
{"success_action_redirect": "http://MYHOSTNAME/form.php?success=true"}, | |
["starts-with", "$Content-Type", ""], | |
["content-length-range", 0, 200000] | |
] }')); | |
$key = 'MY_SECRET_ACCESS_KEY'; | |
$signature = base64_encode(hash_hmac('sha1', $policy, $key, true)); | |
?> | |
<html><head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
</head><body> | |
<form method="POST" enctype="multipart/form-data" action="https://MYBUCKET.s3.amazonaws.com/"> | |
<input type="hidden" name="AWSAccessKeyId" value="MY_ACCESS_KEY_ID" /> | |
<input type="hidden" name="acl" value="public-read" /> | |
<input type="hidden" name="key" value="UUID/${filename}" /> | |
<input type="hidden" name="policy" value='<?php echo $policy; ?>' /> | |
<input type="hidden" name="signature" value="<?php echo $signature; ?>" /> | |
<input type="hidden" name="success_action_redirect" value="http://MYHOSTNAME/form.php?success=true" /> | |
<input type="hidden" name="Content-Type" value="image/png" /> | |
<input type="file" name="file" /> | |
<input type="submit" value="submit"> | |
</form> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment