Skip to content

Instantly share code, notes, and snippets.

@psbolden
Created April 17, 2017 16:52
Show Gist options
  • Save psbolden/b89b24c2473c8084812ccb42875bba45 to your computer and use it in GitHub Desktop.
Save psbolden/b89b24c2473c8084812ccb42875bba45 to your computer and use it in GitHub Desktop.
canvas to s3
source: http://stackoverflow.com/questions/13990673/upload-canvas-data-to-s3
var canvas = document.getElementById("imagePreviewChatFooter");
var dataUrl = canvas.toDataURL("image/jpeg");
var blobData = dataURItoBlob(dataUrl);
var fileName = file.name;
var params = {Key: fileName, ContentType: file.type, Body: blobData};
bucket.upload(params, function (err, data) {
console.log(data);
console.log(err ? 'ERROR!' : 'UPLOADED.');
});
function dataURItoBlob(dataURI) {
var binary = atob(dataURI.split(',')[1]);
var array = [];
for(var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], {type: 'image/jpeg'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment