科尔多瓦正在“废除” cordovan-plugin-file(即将弃用),请参阅其博客文章。
Cordova开发社区将不再对文件传输插件进行任何工作。如果愿意,您可以继续使用文件传输插件-在可预见的将来,它应该可以正常工作。我们强烈建议Cordova用户过渡到使用符合标准的发送和接收二进制数据的方式。
他们鼓励过渡到使用XHR2请求(其中responseType设置为Blob或ArrayBuffer的 XHR请求)。
该博客文章希望提供一个示例,说明如何使用XHR2来获取二进制数据:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile('bot.png', { create: true, exclusive: false }, function (fileEntry) {
console.log('fileEntry is file? ' + fileEntry.isFile.toString());
var oReq = new XMLHttpRequest();
// Make sure you add the domain name to the Content-Security-Policy <meta> element.
oReq.open("GET", "http://cordova.apache.org/static/img/cordova_bot.png", true);
// Define how you want the XHR data to come back
oReq.responseType = "blob";
oReq.onload = function (oEvent) { …Run Code Online (Sandbox Code Playgroud)