我想更新放在 www 目录中的图像,例如:
assets/www/img1.png
assets/www/img2.png
基本上我已经有一堆图像,我想从我的服务器中提取图像并覆盖现有的图像。我在这里阅读 phonegap 指南,但不幸的是我自己无法弄清楚。有人可以帮我解决这个问题吗?
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 版
确实感谢您的帮助。