【问题标题】:phonegap copy a picture from iOS photo-libraryphonegap 从 iOS 照片库复制图片
【发布时间】:2014-02-13 19:52:12
【问题描述】:

我使用 phonegap/cordova (3.3.0) 访问 iOS 相机功能。 相机源设置为库,获取库条目。 如果我从收到 uri 的库中选择一个文件,我想用它来复制文件。

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");
   }
}

文件的目的地应该是文件系统的根路径。

【问题讨论】:

    标签: cordova


    【解决方案1】:

    我明白了。函数有错别字。
    我不得不改变

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

    fileEntry.copyTo...
    

    愚蠢的错误,没看到。现在我可以从其他目录的相机库中复制文件了。

    【讨论】:

    • 嗨@mar​​cel,您能否也发布您的插件偏好版本。我仍然无法做到这一点。我需要你的帮助。谢谢和问候
    【解决方案2】:

    完整示例供任何可能需要的人参考。

    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
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多