2016-01-21 84 views
0

我有以下代码,由于某种原因,即使成功调用回调函数,它仍不能正常工作。Cordova文件创建目录不工作

以下是我所知道的目前工作。

  • 相机能够采取图像和存储它的应用程序的文件夹中缓存
  • 当要在resolveonsuccess函数来创建目录似乎并不要创建的目录,我身体检查应用程序的文件夹,它未创建。
  • 一旦它重命名文件并移动它,我没有得到任何错误回调,只有成功。
  • 文件移动后,它不再在缓存中,文件是否被移动到隐藏文件夹?

任何帮助将不胜感激。

function capturePhoto() { 
     sessionStorage.removeItem('imagepath'); 
     // Take picture using device camera and retrieve image as base64-encoded string 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { 
      quality: 50, 
      destinationType: Camera.DestinationType.FILE_URI 
     }); 
    } 
function onPhotoDataSuccess(imageURI) { 
     // Uncomment to view the base64 encoded image data 
     console.log(imageURI); 

     // Get image handle 
     // 
     var imgProfile = document.getElementById('imgProfile'); 

     // Show the captured photo 
     // The inline CSS rules are used to resize the image 
     // 
     imgProfile.src = imageURI; 
     if (sessionStorage.isprofileimage == 1) { 
      getLocation(); 
     } 
     movePic(imageURI); 
    } 

    // Called if something bad happens. 
    // 
    function onFail(message) { 
     alert('Failed because: ' + message); 
    } 

    function movePic(file) { 
     console.log("Going to move file"); 
     window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError); 
    } 

    //Callback function when the file system uri has been resolved 
    function resolveOnSuccess(entry) { 
     var d = new Date(); 
     var n = d.getTime(); 
     //new file name 
     var newFileName = n + ".jpg"; 
     var myFolderApp = "OCRFolder"; 

     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) { 
        //The folder is created if doesn't exist 
        fileSys.root.getDirectory(myFolderApp, 
          {create: true, exclusive: false}, 
          function (directory) { 
           entry.moveTo(directory, newFileName, successMove, resOnError); 
          }, 
          resOnError); 
        console.log(fileSys.root); 
       }, 
       resOnError); 

    } 

    //Callback function when the file has been moved successfully - inserting the complete path 
    function successMove(entry) { 
     //Store imagepath in session for future use 
     // like to store it in database 
     console.log("Move was success " + entry.fullPath); 
     sessionStorage.setItem('imagepath', entry.fullPath); 
    } 

    function resOnError(error) { 
     alert(error.code); 
    } 

回答

0

我通过重建我的科尔多瓦 - 插件文件的插件解决了这个问题

相关问题