Reputation: 272
i have been trying to get the base64 of a file. however i could not use the plugin for some reason.
window.resolveLocalFileSystemUrl(path, gotFile, fail);
This above code gives me a:
"Property 'resolveLocalFileSystemUrl' does not exist on type 'Window'."
error.
Is there any way to fix it? i have the plugin installed. Also, i have tried(from other stackoverflow answers)
window.resolveLocalFileSystemUri(path, gotFile, fail);
window.resolveLocalFileSystemURL(path, gotFile, fail);
window.resolveLocalFileSystemURI(path, gotFile, fail);
OR if there is another way to retrieve the base64, please assist.
By the way, im using filechoose to open and choose the file.
Upvotes: 1
Views: 1672
Reputation: 272
i have solved the issue by re-installing the plugin.
getFileContentAsBase64(path, callback){
window.resolveLocalFileSystemURL(path, gotFile, fail);
function fail(e){
alert('Cannot found requested file');
}
function gotFile(fileEntry){
fileEntry.file(function (file){
var reader = new FileReader();
reader.onloadend = function(e){
var content = this.result;
callback(content);
}
reader.readAsDataURL(file);
});
}
}
the above code allows you to convert a dataURL(file/image/pdf anything) into base64.
you can call it by:
getFileContentAsBase64(obj.toInternalURL().toString(), function (base64File) {
console.log(base64file);
}
Thanks everyone for the help!
Upvotes: 1
Reputation: 2384
I haven't found anywhere default function name window.resolveLocalFileSystemUri
it's a resolveLocalFileSystemURL
Try Below
resolveLocalFileSystemURL(path, function(entry) {
var nativePath = entry.toURL();
console.log('Native URI: ' + nativePath);
document.getElementById('image').src = nativePath;
});
Source is here
Make sure you have installed file-transfer
plugin.
Upvotes: 0