2014-01-23 124 views
2

我使用phonegap/cordova(3.3.0)來訪問iOS攝像頭功能。 相機的來源設置爲圖書館,以獲取圖書館的條目。 如果我從庫中選擇一個文件,我收到uri,我想用它來複制文件。phonegap從iOS照片庫複製圖片

navigator.camera.getPicture(capSucc, capFail,{ 
     sourceType: Camera.PictureSourceType.PHOTOLIBRARY 
}); 

function capSucc(fileURI){ 
     cpyCtrl.copy(fileURI); 
} 

然後我嘗試從fileURI從localFileSystem獲取文件。我收到一個FileEntry的,但它停在該文件的複製指令:

window.resolveLocalFileSystemURI(sourceFile, onSuccess, onError); 

function onSuccess(fileEntry) { 
    var root = localStorage.rootPath;  //root : /Users/xcode/Library/Application Support/iPhone Simulator/6.0/Applications/2102E3A0-7F22-4C56-A693-EF3CF2A7620F/Documents/ 
    var parentName = root.substring(root.lastIndexOf('/')+1); 
    var parentEntry = new DirectoryEntry(parentName,root); 
    fileEntry.copy(parentEntry, "myPic.jpg", succ, fail); //this is where the problem occurs 
    } 

    function succ(entry){ 
     alert("copy"); 
    } 

    function fail(message){ 
     alert("fail"); 
    } 

    function onError(message){ 
     alert("fileFail"); 
    } 
} 

該文件的目的應該是文件系統的ROOTPATH。

回答

1

我明白了。該函數有一個錯字。
我不得不改變

fileEntry.copy(parentEntry, "myPic.jpg", succ, fail); //this is where the problem occurs 

fileEntry.copyTo... 

愚蠢的錯誤,沒看出來。現在我可以從其他目錄中的相機庫複製文件。

+0

嗨@mar​​cel您可以請張貼您的插件首選項版本。我仍然無法做到這一點。我需要你的幫助。感謝致敬 – BizApps

0

完整的例子供將來參考的人誰可能需要它。

var destinationType = navigator.camera.DestinationType; 

navigator.camera.getPicture(
function(imageURI) { 
    window.resolveLocalFileSystemURI(imageURI, function fileEntrySuccess(fileEntry) { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function directoryEntrySuccess(directoryEntry) { 
      var d = new Date(); 
      var uniqueNewFilename = Date.parse(d) + ".jpg"; 
      fileEntry.moveTo(directoryEntry.root, uniqueNewFilename, function moveFileSuccess(newFileEntry) { 
       var picPath = newFileEntry.fullPath; 
       navigator.camera.cleanup(function(){}, function(){}); 
      }, function(){}); 
     }, function(){}); 
    }, function(){}); 
}, function(message) { 
    navigator.notification.alert(message, function(){}, 'Picture Not Added'); 
}, { 
    quality: 49, 
    allowEdit: true, 
    correctOrientation: true, 
    saveToPhotoAlbum: true, 
    destinationType: destinationType.FILE_URI 
});