Cordova 3.4.0上的文件系统失败,“无法创建目标文件” [英] FileSystem on Cordova 3.4.0 fails "Could not create target file"
问题描述
我最近将iOS Cordova专案从2.7.0升级到3.4.0。
升级文件系统访问后断开。 (似乎在模拟器中工作吗?)
我收到一条错误消息,指出无法创建目标文件,我googled周围想到改变我的全路径到toURL(),但没有效果。
$ b
这里是我的下载代码
c $ c> window.requestFileSystem(LocalFileSystem.PERSISTENT,0,
function onFileSystemSuccess(fileSystem){
fileSystem.root.getFile(
dummy.html ,{
create:true,
exclusive:false
},
函数gotFileEntry(fileEntry){
var sPath = fileEntry.toURL .replace(dummy.html,);
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download bhttps://dl.dropbox.com/u/13253550/db02.xml,
sPath +database.xml,
函数(theFile){
console.log(download complete:+ theFile.toURI());
showLink(theFile.toURI());
setTimeout(function(){
checkConnection();
},50);
},
function(error){
console.log(download error source+ error.source);
console.log(download error target+ error.target);
console.log(upload error code:+ error.code);
});
},
fail);
},
fail);
我发现文件插件a href =https://github.com/apache/cordova-plugin-file/blob/dev/doc/index.md =nofollow>链接)和fileTransfer插件(链接)
进行原始问题中提到的更改后,我想知道文件插件部分是否正确,并开始查找我的fileTransfer代码和提供的示例之间的差异。
原来我没有在我的下载源url(doh)
上做encodeURI(),所以完整的工作代码:
window.requestFileSystem(
LocalFileSystem.PERSISTENT,0,
function onFileSystemSuccess(fileSystem){
fileSystem.root.getFile(
dummy.html,{
create:true,
exclusive:false
},
function gotFileEntry fileEntry){
var sPath = fileEntry.toURL()。replace(dummy.html,);
var fileTransfer = new FileTransfer();
fileEntry.remove();
var DBuri = encodeURI(https://dl.dropbox.com/u/13253550/db02.xml);
fileTransfer.download(
DBuri,
sPath +database.xml,
function(theFile){
console.log :+ theFile.toURI());
showLink(theFile.toURI());
setTimeout(function(){
checkConnection();
},50);
},
function(error){
console.log(download error source+ error.source);
console.log + error.target);
console.log(upload error code:+ error.code);
});
},
fail);
},
fail);
I recently upgraded my iOS Cordova project from 2.7.0 to 3.4.0.
After upgrading filesystem access is broken. (seems to work in the simulator though?)
I get an error message stating "Could not create target file", I googled around and thought to change my "fullpath" to "toURL()" but to no avail. I really don't know what to try next?
here's my download code
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {
create: true,
exclusive: false
},
function gotFileEntry(fileEntry) {
var sPath = fileEntry.toURL().replace("dummy.html", "");
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
"https://dl.dropbox.com/u/13253550/db02.xml",
sPath + "database.xml",
function (theFile) {
console.log("download complete: " + theFile.toURI());
showLink(theFile.toURI());
setTimeout(function () {
checkConnection();
}, 50);
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
});
},
fail);
},
fail);
I found the documentation for both the file plugin ( link) and the fileTransfer plugin ( link)
After making the change noted in the original question, I wondered if the file plugin part was OK and started looking for discrepancies between my fileTransfer code and the examples provided.
Turns out I wasn't doing encodeURI() on my download source url (doh)
so the complete, working code:
window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {
create: true,
exclusive: false
},
function gotFileEntry(fileEntry) {
var sPath = fileEntry.toURL().replace("dummy.html", "");
var fileTransfer = new FileTransfer();
fileEntry.remove();
var DBuri = encodeURI("https://dl.dropbox.com/u/13253550/db02.xml");
fileTransfer.download(
DBuri,
sPath + "database.xml",
function (theFile) {
console.log("download complete: " + theFile.toURI());
showLink(theFile.toURI());
setTimeout(function () {
checkConnection();
}, 50);
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code: " + error.code);
});
},
fail);
},
fail);
这篇关于Cordova 3.4.0上的文件系统失败,“无法创建目标文件”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!