Created
April 17, 2017 16:52
-
-
Save psbolden/b89b24c2473c8084812ccb42875bba45 to your computer and use it in GitHub Desktop.
canvas to s3
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
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