Created
March 25, 2016 04:05
-
-
Save brycefisher/13733c17e39f51d7c919 to your computer and use it in GitHub Desktop.
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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Play Time</title> | |
</head> | |
<body> | |
<form> | |
<input type="file" id="file-chooser" /> | |
<button id="upload-button">Upload to S3</button> | |
<div id="results"></div> | |
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.2.46.min.js"></script> | |
<script type="text/javascript"> | |
// See the Configuring section to configure credentials in the SDK | |
AWS.config.credentials = { | |
accessKeyId: 'FIND_YOUR_OWN_KEY', | |
secretAccessKey: 'FIND_YOUR_OWN_KEY' | |
}; | |
// Configure your region | |
AWS.config.region = 'us-west-1'; | |
</script> | |
<script type="text/javascript"> | |
var bucket = new AWS.S3({params: {Bucket: 'YOUR_BUCKET'}}); | |
var fileChooser = document.getElementById('file-chooser'); | |
var button = document.getElementById('upload-button'); | |
var results = document.getElementById('results'); | |
button.addEventListener('click', function(e) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
var file = fileChooser.files[0]; | |
if (file) { | |
results.innerHTML = ''; | |
var params = {Key: file.name, ContentType: file.type, Body: file}; | |
bucket.upload(params, function (err, data) { | |
results.innerHTML = err ? 'ERROR!' : 'UPLOADED.'; | |
}); | |
} else { | |
results.innerHTML = 'Nothing to upload.'; | |
} | |
}, false); | |
</script> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment