我是移动开发的初学者。我需要从服务器下载图像文件,以在应用程序页面上进一步使用。我尝试使用插件文件传输。
JS:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.getElementById("downloadFile").addEventListener("click", downloadFile);
}
function downloadFile() {
var fileTransfer = new FileTransfer();
var uri = encodeURI("http://cp35240-wordpress.tw1.ru/wp-content/uploads/2018/11/img_7705.jpg");
var fileURL = "///storage/emulated/0/DCIM/myFile";
fileTransfer.download(
uri, fileURL,
function(entry) {
console.log("download complete: " + entry.toURL());
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("download error code" + error.code);
},
false, {
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
}
HTML:
<body onload="onLoad()">
<div class="panel">
<a href="#" id="menu"><img src="img/menu.svg"></a>
<a href="settings.html" id="settings"><img src="img/settings.svg"></a>
<a href="notifications.html" id="notification"><img src="img/notification.svg"></a>
</div>
<div id="mainpage">
<button id="downloadFile">DOWNLOAD</button>
</div>
该代码不起作用。也许有什么想法?