2014-01-23 213 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 
});