Created
September 18, 2015 20:55
-
-
Save kaiiserni/6819bd964796a239f1d0 to your computer and use it in GitHub Desktop.
upload file to s3
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
// in de head eerst volgend scriptje requiren: <script src="https://sdk.amazonaws.com/js/aws-sdk-2.2.3.min.js"></script> | |
AWS.config.region = 'eu-west-1'; | |
var bucket = new AWS.S3({params: {Bucket: 'demuziekwedstrijd-upload'}}); | |
var veld = document.getElementById('upload_veld'); | |
var button = document.getElementById('upload_knop'); | |
button.addEventListener('click', function() { | |
var file = veld.files[0]; | |
if (file) { | |
// naam ophalen | |
var http = new httpRequest(); | |
http.onreadystatechange=function(){ | |
if (http.readyState==4 && http.status==200){ | |
var kanga_name = http.responseText; // bestandsnaam | |
// bestand uploaden | |
var params = {Key: "uploads/" + kanga_name + file.name.split(".")[1], ContentType: file.type, Body: file}; | |
bucket.upload(params, function (err, data) { | |
alert(err ? 'ERROR!' : 'SUCCESS!'); | |
}); | |
} | |
} | |
http.open("GET", create_video_url_met_alle_parameters,true); | |
http.send(); | |
} else { | |
// Geen file gevonden? | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment