问题
I'm trying to load a file from a server and save it on the device. This code used to work in Phonegap 3.1, and it's still working fine with 3.4 on Android. But when I run the same code on iOS 7.1. I got an error saying,
{
"code":1,
"source":"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400",
"target":null,
"http_status":200,
"body":"Could not create target file"
}
Here's my code.
var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI('http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400'), '/com.mee.flight/maptile/70400', function (entry) {
//Do something
});
At first I thought the solution is straight forward, since Phonegap actually tells me that there's something wrong with the target file. So, I fiddled with the file path, but they didn't really work out. Any idea?
回答1:
I figured this out already. In case anyone's having the same problem, the solution is to use 'cdvfile://localhost/persistent/' to get to the root folder in Phonegap. So, in my case, the change would be,
var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI('http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/18/96730/70400'), 'cdvfile://localhost/persistent/com.mee.flight/maptile/70400', function (entry) {
//Do something
});
来源:https://stackoverflow.com/questions/23097188/phonegap-3-4-filetransfer-error-ios