Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ex-Ark/bcd1898fc3cdeae6598881ee8cb49177 to your computer and use it in GitHub Desktop.
Save Ex-Ark/bcd1898fc3cdeae6598881ee8cb49177 to your computer and use it in GitHub Desktop.
Creates a pure HTML form for a browser-based upload to a AWS S3 compatible server ( like Minio )
presigned_json = {:fields=>{:AWSAccessKeyId=>nil, :key=>"1530784425_light", :policy=>"eyJleHBpcmF0aW9uIjoiMjAxOC0wNy0wNVQxMDoxODo0NVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJhM2JjdXNlcnMifSx7ImtleSI6IjE1MzA3ODQ0MjVfbGlnaHQifSx7ImFjbCI6InB1YmxpYy1yZWFkIn0sWyJzdGFydHMtd2l0aCIsIiRDb250ZW50LVR5cGUiLCJpbWFnZS8iXSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwxLDEwMjQwMDAwMF0seyJ4LWFtei1jcmVkZW50aWFsIjoiYTNiY2FjY2Vzcy8yMDE4MDcwNS9ldS13ZXN0LTMvczMvYXdzNF9yZXF1ZXN0In0seyJ4LWFtei1hbGdvcml0aG0iOiJBV1M0LUhNQUMtU0hBMjU2In0seyJ4LWFtei1kYXRlIjoiMjAxODA3MDVUMDk1MzQ1WiJ9XX0=", "x-amz-signature"=>"8e8d3987682ef7793cf0aca381fe7174155ebfa131cf509b94bffd29da2fb1cb", "x-amz-credential"=>"a3bcaccess/20180705/eu-west-3/s3/aws4_request", "x-amz-date"=>"20180705T095345Z", "x-amz-algorithm"=>"AWS4-HMAC-SHA256", :acl=>"public-read"}, :upload_url=>"http://minio:9000/a3bcusers", :download_url=>"http://minio:9000/a3bcusers/1530784425_light"}
json = presigned_json[:fields]
out = []
out << '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="http://localhost:9000/a3bcusers" method="post" enctype="multipart/form-data">
Key to upload: '
out << "
<input type=\"input\" name=\"key\" value=\"#{json[:key]}\" /><br />"
out << " <input type=\"hidden\" name=\"acl\" value=\"#{json[:acl]}\" />"
out << 'Content-Type:
<input type="input" name="Content-Type" value="image/png" /><br />'
out << "
<input type=\"text\" name=\"X-Amz-Credential\" value=\"#{json['x-amz-credential']}\" />"
out << "
<input type=\"text\" name=\"X-Amz-Algorithm\" value=\"#{json['x-amz-algorithm']}\" />"
out << "
<input type=\"text\" name=\"X-Amz-Date\" value=\"#{json['x-amz-date']}\" />
"
out << '
Tags for File:
<input type="input" name="x-amz-meta-tag" value="" /><br />
'
out << "
<input type=\"hidden\" name=\"Policy\" value=\"#{json[:policy]}\" />"
out << "
<input type=\"hidden\" name=\"X-Amz-Signature\" value=\"#{json['x-amz-signature']}\" />"
out << '
File:
<input type="file" name="file" /> <br />
<!-- The elements after this will be ignored -->
<input type="submit" name="submit" value="Upload to Amazon S3" />
</form>
</html>
'
o = File.open('out.html','w')
o.puts out
@Ex-Ark
Copy link
Author

Ex-Ark commented Jul 5, 2018

To use simply open 'out.html' with your browser.( firefox out.html).
Form values are pre-filled with json hash given.You can edit some, choose the file to upload and then click upload button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment