2016-06-28 10 views
2

こんにちは、Phonegapを使用してiOSアプリケーションを作成しています。私は画像ファイルをダウンロードするためにFiletransfer APIを使用しています。Phonegap iOSでファイルをダウンロード中にエラーが発生しました

FileTransferError { 
    body = "Could not create path to save downloaded file: You don\U2019t have permission to save the file \U201cMyRecipeDirectory\U201d in the folder \U201cMonarch13A452.J72OS\U201d."; 
    code = 1; 
    "http_status" = 200; 
    source = "https://www.facebookbrand.com/img/fb-art.jpg"; 
    target = "cdvfile://localhost/root/MyDirectory/test.jpg"; 
} 

どのように私はこれを解決するのです:私は、私はiOSデバイス上でそれを実行すると、私はエラーを取得していますファイル

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, createFolder, null); 

    function createFolder(fileSystem) { 
     console.log('gotFS'); 
     fileSystem.root.getDirectory("MyDirectory", { 
          create: true, 
          exclusive: false 
          }, MyDirectorySuccess, MyDirectoryfail); 
    } 

    function MyDirectorySuccess(entry) { 
     console.log('gotDirectorySuccess'); 
     downloadFile(entry); 
    } 
    function downloadFile(entry) 
    { 
     console.log('downloadFile'); 

     var filePath = entry.fullPath+'test.jpg'; 
     var fileTransfer = new FileTransfer(); 
     var url = 'https://www.facebookbrand.com/img/fb-art.jpg'; 

     fileTransfer.download(
         url, filePath, function(entry) { 
         console.log("success"); 
         }, function(error) { 
         console.log("error"); 
         }, true, {}); 
    } 

をダウンロードするには、次のコードを使用していますか?

答えて

1

これは、cordova-plugin-file-transferとcordova-plugin-fileプラグインの複雑なバグです。
FileTransferプラグインはFileプラグインに "root"タイプを使用しています。これはデフォルトであり、どのタイプも変更することはできません。
"root"のパスは "/"です。これが問題の原因です。
例えば、 "persistent"のパスは "/ user/{your name}/Library/..."です。
「/」にアクセスすることはできません。

getAvailableFileSystems()メソッドのCordovaLib.xcodeprojのCDVFile.mで@ "root"パスを変更しようとしました。
しかし、アプリは設定後にクラッシュしました。
スマートな方法はありません、私は不自然に弦を変更する方法を取ることにしました。
CDVFileTransfer.mラインで

ダウンロード()メソッド440

target = [target stringByReplacingOccurrencesOfString:@"//" withString:@"/"]; 
targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url; 

は、この下のコードを追加します。

NSString *absoluteURL = [targetURL absoluteString]; 
if ([absoluteURL hasPrefix:@"cdvfile://localhost/root/"]) { 
     absoluteURL = [absoluteURL stringByReplacingOccurrencesOfString:@"cdvfile://localhost/root/" withString:@"cdvfile://localhost/persistent/"]; 
     targetURL = [NSURL URLWithString:absoluteURL]; 
} 
関連する問題