Created
April 6, 2015 22:17
-
-
Save danecando/92ef9240c6ab715f35c4 to your computer and use it in GitHub Desktop.
Cordova Meteor Slingshot
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
| window.resolveLocalFileSystemURL(imageUri, function(fileEntry) { | |
| fileEntry.file(function(file) { | |
| file.name = filename; | |
| template.cordovaFile = file; | |
| }); | |
| }); | |
| var file = template.cordovaFile; | |
| var reader = new FileReader(); | |
| reader.onloadend = function(e) { | |
| var fileBlob = internals.dataURItoBlob(e.target.result); | |
| if (fileBlob) { | |
| uploader.send(fileBlob, function (error, downloadUrl) { | |
| if (error) { | |
| return cb(error); | |
| } | |
| return cb(null); | |
| }); | |
| } | |
| } | |
| reader.readAsDataURL(file); | |
| /** | |
| * Converts a data uri into Blob object | |
| * @param dataURI | |
| * @returns {Blob} | |
| */ | |
| internals.dataURItoBlob = function(dataURI) { | |
| var byteString = atob(dataURI.split(',')[1]); | |
| var ab = new ArrayBuffer(byteString.length); | |
| var ia = new Uint8Array(ab); | |
| for (var i = 0; i < byteString.length; i++) { | |
| ia[i] = byteString.charCodeAt(i); | |
| } | |
| return new Blob([ab], { type: 'image/jpeg' }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment