Javascript 从URI获取文件base64
我一直在尝试获取文件的base64。但是由于某些原因,我不能使用插件Javascript 从URI获取文件base64,javascript,cordova,typescript,ionic-framework,ionic2,Javascript,Cordova,Typescript,Ionic Framework,Ionic2,我一直在尝试获取文件的base64。但是由于某些原因,我不能使用插件 window.resolveLocalFileSystemUrl(path, gotFile, fail); 上述代码为我提供了一个: “类型'Window'上不存在属性'resolveLocalFileSystemUrl'。” 错误 有没有办法解决这个问题?我已经安装了插件。此外,我也尝试过(从其他答案) 或者,如果有其他方法检索base64,请提供帮助 顺便说一下,我使用filechoose打开并选择文件。我没有找到任何
window.resolveLocalFileSystemUrl(path, gotFile, fail);
上述代码为我提供了一个:
“类型'Window'上不存在属性'resolveLocalFileSystemUrl'。”
错误
有没有办法解决这个问题?我已经安装了插件。此外,我也尝试过(从其他答案)
或者,如果有其他方法检索base64,请提供帮助
顺便说一下,我使用filechoose打开并选择文件。我没有找到任何默认函数名
窗口。resolveLocalFileSystemUri
它是一个resolveLocalFileSystemURL
试试下面
resolveLocalFileSystemURL(path, function(entry) {
var nativePath = entry.toURL();
console.log('Native URI: ' + nativePath);
document.getElementById('image').src = nativePath;
});
来源是
确保您已安装
文件传输
插件。我已通过重新安装插件解决了问题
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(file/image/pdf-anything)转换为base64
您可以通过以下方式调用它:
getFileContentAsBase64(obj.toInternalURL().toString(), function (base64File) {
console.log(base64file);
}
谢谢大家的帮助 我能想到的两件事1。无论你在哪里使用插件add
declarevar窗口代码>在它上面。2.使用platform.readyplatform.ready()。然后(()=>{window.resolveLocalFileSystemURL(path,(dir)=>{…});
让我知道哪个选项works@Lyon,请检查并@OlegEstekhin-oops我不知道。谢谢你指出它!!我也接受了其他帖子的答案!:)
getFileContentAsBase64(obj.toInternalURL().toString(), function (base64File) {
console.log(base64file);
}