Skip to content

Instantly share code, notes, and snippets.

@brunohaveroth
Created September 20, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunohaveroth/506e17430a027300886e7f44e2f7f1bd to your computer and use it in GitHub Desktop.
Save brunohaveroth/506e17430a027300886e7f44e2f7f1bd to your computer and use it in GitHub Desktop.
navigator.camera.getPicture((data)=> {
var byteCharacters = atob(data);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: 'image/jpg'});
var form = new FormData();
form.append("product-image", blob);
this.set('uploadForm', form);
this.renderPreview(blob);
}, function() {
alert('Falha ao escolher a imagem');
}, {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment