Cordova Phonegap Filetransfert下载:API错误时创建文件

Cordova Phonegap Filetransfert下载:API错误时创建文件,cordova,download,Cordova,Download,我正在使用fileTransfer.download方法从服务器检索PNG文件 但是,当我尝试下载一个不存在的文件时,API会在我手机的文件系统上创建一个大小为0位的文件(给它传递给下载方法的名称) 如果这是一种正常的行为,我希望在出现错误时不会创建文件 我可以用一些代码手动删除文件,但我想知道这是否真的需要,或者我是否误用了API 我使用的是2.2.0版 非常感谢 致以最良好的祝愿 弗洛伦特。我已经在安卓系统中试用过,希望它也能在IOS上使用 enter code here function

我正在使用fileTransfer.download方法从服务器检索PNG文件

但是,当我尝试下载一个不存在的文件时,API会在我手机的文件系统上创建一个大小为0位的文件(给它传递给下载方法的名称)

如果这是一种正常的行为,我希望在出现错误时不会创建文件

我可以用一些代码手动删除文件,但我想知道这是否真的需要,或者我是否误用了API

我使用的是2.2.0版

非常感谢

致以最良好的祝愿


弗洛伦特。

我已经在安卓系统中试用过,希望它也能在IOS上使用

enter code here
 function fun(){
var dfd = $.Deferred(function (dfd){
var remoteFile = "Your link";
var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/')+1);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile(localFileName, {create: true, exclusive: false},
    function(fileEntry) {
var localPath = fileEntry.fullPath;
if (device.platform === "Android" && localPath.indexOf("file://") === 0) {
            localPath = localPath.substring(7);
            }// You need to write IOS instead of Android

    var ft = new FileTransfer();
    ft.download(remoteFile, localPath, function(entry) {
    dfd.resolve('file downloaded');
     // Do what you want with successful file downloaded and then
    // call the method again to get the next file
    //downloadFile();
            }, fail);
             }, fail);
            }, fail);

           });
            return dfd.promise();

        }
                fun().then(function(msg){
            if(msg==="file downloaded")
            {
            alert("Download complete");
            }
            else
            {
            alert("Download error")
            }
            });
            function fail(){
            alert("error");
        }

嘿,看看我的答案-

让我知道。如果还有什么问题。 在config.xml中包括以下内容

对于安卓系统-

<feature name="http://api.phonegap.com/1.0/file" />
<feature name="File">
       <param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
      <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Storage">
       <param value="org.apache.cordova.Storage" name="android-package"/>
</feature>

对于IOS-

<plugin name="File" value="CDVFile" />
<plugin name="FileTransfer" value="CDVFileTransfer" />