This commit is contained in:
Jesse MacFadyen 2014-05-08 15:31:46 -07:00
commit 707426ece2

View File

@ -133,14 +133,13 @@ module.exports = {
// because of asynchronous method, so let the successCallback be called in it. // because of asynchronous method, so let the successCallback be called in it.
var resizeImageBase64 = function (file) { var resizeImageBase64 = function (file) {
var imgObj = new Image();
var success = function (fileEntry) { Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
var successCB = function (filePhoto) { var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
var fileType = file.contentType, var imageData = "data:" + file.contentType + ";base64," + strBase64;
reader = new FileReader();
reader.onloadend = function () {
var image = new Image(); var image = new Image();
image.src = reader.result; image.src = imageData;
image.onload = function() { image.onload = function() {
var imageWidth = targetWidth, var imageWidth = targetWidth,
@ -154,34 +153,14 @@ module.exports = {
ctx.drawImage(this, 0, 0, imageWidth, imageHeight); ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
// The resized file ready for upload // The resized file ready for upload
var finalFile = canvas.toDataURL(fileType); var finalFile = canvas.toDataURL(file.contentType);
// Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API. // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
var arr = finalFile.split(","); var arr = finalFile.split(",");
var newStr = finalFile.substr(arr[0].length + 1); var newStr = finalFile.substr(arr[0].length + 1);
successCallback(newStr); successCallback(newStr);
}; };
};
reader.readAsDataURL(filePhoto);
};
var failCB = function () {
errorCallback("File not found.");
};
fileEntry.file(successCB, failCB);
};
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
success(new FileEntry(storageFile.name, "ms-appdata:///local/" + storageFile.name));
}, function () {
fail(FileError.INVALID_MODIFICATION_ERR);
}, function () {
errorCallback("Folder not access.");
}); });
}; };
if (sourceType != Camera.PictureSourceType.CAMERA) { if (sourceType != Camera.PictureSourceType.CAMERA) {