I have the following path
"file:///var/mobile/Containers/Data/Application/92C91B4A-B7F9-40F8-B8AD-646DA0607942/Library/NoCloud/Z7sY4cdv_photo_001.jpg"
how can I convert this file path to the actual binary representation of the file? I've tried using the file reader in every way imaginable but keep on getting error codes. THANKS
so my expect result is to have the bytes into a javaScript object, basically assign a image to a object.
try that :
$scope.getFileBinary = function(fileUri){
var xhr = new XMLHttpRequest();
xhr.open("GET", fileUri, true);
//xhr.responseType = 'blob';
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
var uInt8Array = new Uint8Array(this.response);
if (this.status == 200 || this.status === 0) {
// Note: .response instead of .responseText
var blob = new Blob([this.response], {
type: 'image/png'
});
var reader = new FileReader();
reader.onload = function() {
// this gets read of the mime-type data header
var actual_contents = reader.result.slice(reader.result.indexOf(',') + 1);
d.resolve(actual_contents );
};
reader.readAsDataURL(blob);
}
};
xhr.send();
}