我正在尝试在FileEntry上执行copyTo方法,并且它的失败错误代码为1.我怀疑我没有给它它需要的东西。这是我为方法提供的输入,其中一个值是不正确的?在Android上运行但也在iOS上获得错误。我试图按照API文档中的说明进行操作,但预期输入不明确。
var imageUri = 'file:///mnt/sdcard/Android/data/com.test.app/cache/resize.jpg?1337214925787';
var newFileName = 'test.jpg';
var directoryFullPath = 'file:///mnt/sdcard/App/Job';
window.resolveLocalFileSystemURI(
imageUri,
function (entry) {
console.log("Get file entry success, copy file");
var parentEntry = new DirectoryEntry({ fullPath: directoryFullPath});
entry.copyTo(
parentEntry,
newFileName,
function (newEntry) {
console.log("FileEntry copy to done. New Path: " + newEntry.fullPath);
},
function (error) {
console.log("FileEntry copy to fail. Error code: " + error.code);
}
...
答案 0 :(得分:1)
我构建了我的代码,就像这篇文章中的示例一样,并且能够成功执行。也许这是一个我没有看到的封闭问题,不确定,但下面的示例有效。
仅供参考,如果文件已经存在,它看起来会抛出一个错误,所以我不得不修改我的代码,为文件名添加一个时间戳来防止这种情况发生。