我一直在尝试获取文件的 base64。但是由于某种原因我无法使用该插件。
window.resolveLocalFileSystemUrl(path, gotFile, fail);
上面的代码给了我一个:
“类型 'Window' 上不存在属性 'resolveLocalFileSystemUrl'。”
错误。
有什么办法可以解决吗?我安装了插件。另外,我已经尝试过(来自其他 stackoverflow 答案)
window.resolveLocalFileSystemUri(path, gotFile, fail);
window.resolveLocalFileSystemURL(path, gotFile, fail);
window.resolveLocalFileSystemURI(path, gotFile, fail);
或者,如果有其他方法可以检索 base64,请提供帮助。
顺便说一句,我使用 filechoose 打开并选择文件。
我已经通过重新安装插件解决了这个问题。
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);
});
}
}
上面的代码允许您将 dataURL(文件/图像/pdf 任何内容)转换为 base64。
您可以通过以下方式调用它:
getFileContentAsBase64(obj.toInternalURL().toString(), function (base64File) {
console.log(base64file);
}
感谢大家的帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句