2016-06-28 3 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/..."입니다.
"/"에 액세스 할 수 없습니다.

CordovaLib.xcodeproj의 getAvailableFileSystems() 메소드 CDVFile.m에서 @ "root"경로를 수정하려고했습니다.
그러나 앱을 설정 한 후 앱이 다운되었습니다.
똑똑한 방법이 없습니다. 나는 부 자연스럽게 문자열을 바꾸는 방법을 선택했습니다. (440)

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

추가 코드이 아래 CDVFileTransfer.m 라인에서

다운로드() 메소드.

NSString *absoluteURL = [targetURL absoluteString]; 
if ([absoluteURL hasPrefix:@"cdvfile://localhost/root/"]) { 
     absoluteURL = [absoluteURL stringByReplacingOccurrencesOfString:@"cdvfile://localhost/root/" withString:@"cdvfile://localhost/persistent/"]; 
     targetURL = [NSURL URLWithString:absoluteURL]; 
} 
관련 문제