2017-05-08 99 views
1

我一直在试图获取文件的base64。但是由于某种原因,我无法使用该插件。从URI获取文件base64

window.resolveLocalFileSystemUrl(path, gotFile, fail); 

这上面的代码给了我:

“属性‘resolveLocalFileSystemUrl’对类型‘窗口’不存在”

错误。

有什么方法可以解决它吗?我已经安装了插件。另外,我有尝试过(从其他计算器答案)

window.resolveLocalFileSystemUri(path, gotFile, fail); 
window.resolveLocalFileSystemURL(path, gotFile, fail); 
window.resolveLocalFileSystemURI(path, gotFile, fail); 

,或者如果有另一种方式来检索的base64,请协助。

顺便说一句,即时通讯使用filechoose打开并选择文件。

+0

2我能想到的东西 1.无论你在使用插件,在其上添加'declare var window;'。 2.使用该内部platform.ready 'platform.ready(),然后(()=> { window.resolveLocalFileSystemURL(路径,(DIR)=> { ... } });' 让我知道哪个选项有效 –

+0

@Lyon,请查看https://meta.stackoverflow.com/questions/309266/updated-actively-prevent-this-in-title-not-solved-yet和http:// stackoverflow。 com/help/accepted-answer –

+0

@OlegEstekhin哎呀我不知道它。谢谢指出它!我也接受了我的其他帖子的答案!:) – Lyon

回答

0

我已通过重新安装插件解决了该问题。

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); 
} 

感谢大家的帮助!

0

我还没有发现任何地方默认的函数名window.resolveLocalFileSystemUri这是一个resolveLocalFileSystemURL

试试下面

resolveLocalFileSystemURL(path, function(entry) { 
    var nativePath = entry.toURL(); 
    console.log('Native URI: ' + nativePath); 
    document.getElementById('image').src = nativePath; 
}); 

来源是here

确保你已经安装了file-transfer插件。