I found a way. I’m using https://github.com/wymsee/cordova-imagePicker // it gives me the paths to the file and it took me some time to figure out how to make those URI’s to actual blobs that can be used by something like Slingshot. But I do something like this, even thought it’s probably ugly:
imagePick = function() {
window.imagePicker.getPictures(
function(results) {
var blobArray = [];
for (var i = 0; i < results.length; i++) {
console.log(results[i]);
console.log(“test sequence”);
if (window.File && window.FileReader && window.FileList && window.Blob) {
} else {
console.log(‘The File APIs are not fully supported in this browser.’);
}
var filePathFull = results[i];
var fileName = filePathFull.split(“cache/”)[1];
readFromFile(fileName, function(blob) {
console.log(blob);
blobArray.push(blob);
if (blobArray.length == i) {
console.log("----- upload simulation ----- file: " + blob.name);
console.log(blob.orderNo);
multiUpload(blobArray)
}
});
}
}, function (error) {
console.log('Error: ’ + error);
}
);
};
function readFromFile(fileName, callback) {
var pathToFile = cordova.file.applicationStorageDirectory + “cache/” + fileName;
window.resolveLocalFileSystemURL(pathToFile, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function (e) {
console.log("reader.onloadened");
//alert(JSON.stringify(this.result, null, 4));
var byteString = this.result.split(',')[1];
//alert(JSON.stringify(byteString, null, 4));
b64toBlob(byteString, fileName, null, null, callback);
};
reader.readAsDataURL(file);
}, errorHandler.bind(null, fileName));
}, errorHandler.bind(null, fileName));
}
errorHandler = function (fileName, e) {
var msg = ‘’;
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'Storage quota exceeded';
break;
case FileError.NOT_FOUND_ERR:
msg = 'File not found';
break;
case FileError.SECURITY_ERR:
msg = 'Security error';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'Invalid modification';
break;
case FileError.INVALID_STATE_ERR:
msg = 'Invalid state';
break;
default:
msg = 'Unknown error';
break;
}
console.log('Error (' + fileName + '): ' + msg);
};
b64toBlob = function(b64Data, fileName, contentType, sliceSize, callback) {
console.log(“window.resolveLocalFileSystemURL”);
contentType = contentType || ‘image/jpeg’;
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
blob.orderNo = UserLastOrder;
blob.name = fileName;
console.log("blobbed");
callback(blob);
return blob;
};
I know that some lines like the last return blob; at the end are uneccesary but that is the code that is working right now but i haven’t cleaned it up so I post how it’s working for me