我想更新www目录中的图片,例如:
assets/www/img1.png
assets/www/img2.png
基本上我已经有一堆图像了,我想从我的服务器中提取图像并覆盖现有的图像。我正在阅读电话空白指南here,但不幸的是我无法弄清楚自己。有人可以帮我这个吗?
var imgNames = ["www.foo.com/img1.png","www.foo.com/img2.png"];
for(var i=0; i < imgNames .length; i++){
toDlPath = imgNames[i].substring(imgNames[i].lastIndexOf("/") +1); //e.g. img1.png
ft = new FileTransfer();
ft.download(imgNames[i], dlPath, function(e){
console.log("Successful download of "+e.fullPath);
}, function(e){
console.log("error while saving img:");
console.log(e);
});
}
我尝试使用FileTransfer,但收到此错误(在Android上测试):
09-28 14:32:14.437: E/FileTransfer(11017): {"target":"img1.png","source":"http:\/\/foo.com\/img1.png","code":1}
09-28 14:32:14.437: E/FileTransfer(11017): java.io.FileNotFoundException
09-28 14:32:14.437: E/FileTransfer(11017): at org.apache.cordova.FileTransfer.getFileFromPath(FileTransfer.java:556)
09-28 14:32:14.437: E/FileTransfer(11017): at org.apache.cordova.FileTransfer.download(FileTransfer.java:444)
09-28 14:32:14.437: E/FileTransfer(11017): at org.apache.cordova.FileTransfer.execute(FileTransfer.java:88)
09-28 14:32:14.437: E/FileTransfer(11017): at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:186)
09-28 14:32:14.437: E/FileTransfer(11017): at java.lang.Thread.run(Thread.java:856)
Phonegap版本1.8.1
确实非常感谢你的帮助。