2016-11-11 52 views
0

我收到照片,我想顯示它們(它的工作)並將它們保存在我的目錄中。我遵循這個論壇和W3C的混合反應來獲得這個代碼。我的問題是,當我得到fileSys目錄時,它轉到onError,它不能得到myFolderApp目錄。顯示屏中顯示「錯誤5獲取目錄時,我在科爾多瓦應用程序拍照

未能確保目錄: /storage/sdcard1/Android/data/tta.kirolapp.v1/files

未能確保目錄: /storage/sdcard1/Android/data/tta.kirolapp.v1/files

這是正常的,因爲應用程序def行兇目錄

/storage/emulated/0/0Android/data/tta.kirolapp.v1/

所以,我認爲這是問題,但我不知道如何解決它。 的這需要照片並管理它的功能的代碼,是下一個:

function capturePhoto() { 
    alert('on capturePhoto'); 

    sessionStorage.removeItem('imagepath'); 
    //Cogemos la imagen y la codificamos en Base64 
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, cameraDirection: 1, saveToPhotoAlbum:true, destinationType: Camera.DestinationType.FILE_URI }); 
} 

function onPhotoDataSuccess(imageURI) { 
     // Uncomment to view the base64 encoded image data 
     // console.log(imageData); 

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

     // Pasamos la imagen a pantalla desde imageURI 
     // 
     console.log('El url por defecto es: '+ imageURI); 
     imgProfile.src = imageURI; 
     if(sessionStorage.isprofileimage==1){ 
      getLocation(); 
     } 
     movePic(imageURI); 
} 

// Funcion onError 
// 
function onFail(message) { 
    alert('Failed because: ' + message); 
} 

function movePic(file){ 
    window.resolveLocalFileSystemURL(file, resolveOnSuccess, resOnError); 
} 

//Callback function when the file system uri has been resolved 
function resolveOnSuccess(entry){ 
    console.log("Estoy en resolveOnSuccess"); 
    var d = new Date(); 
    var n = d.getTime(); 
    //new file name 
    var identificacion= $('#idEmailReg').val(); 
    var newFileName="foto"+identificacion+".jpg"; 
    console.log ('El newFileName es: '+ newFileName); 
    var myFolderApp = "file:///storage/emulated/0/Android/data/tta.kirolapp.v1/img/"; 
     //appConstants.localPermanentStorageFolderImg; 
    console.log ('El nuevo directorio es: '+ myFolderApp); 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {  
    console.log ('Entramos en el request onSuccess'); 
    //The folder is created if doesn't exist 
    fileSys.root.getDirectory(myFolderApp, 
        {create:true, exclusive: false}, 
        function(directory) { 
         console.log('El directory es: '+ directory); 
         entry.moveTo(directory, newFileName, successMove, resOnError); 
        }, 
        resOnError); 
        }, 
    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 

    sessionStorage.setItem('imagepath', entry.fullPath); 
} 

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

resOnError示出了代碼「5」,以及監視器輸出是下一個: enter image description here

回答

0

我使用的介質插件,並採取與照片拍攝照片,這是代碼:

function capturePhoto(){ 
    //var fileFolder="/storage/emulated/0/KirolApp/img/"; 
    var fileFolder=appConstants.localPermanentStorageFolderImg(); 
    var identificacion= $('#idEmailReg').val(); 
    var fileName="foto"+identificacion+".jpg"; 
    photo.takeAsync(
     fileFolder, 
     fileName, 
     function() { 
      console.log('En capturePhoto funcion'); 
      var urlCompleta=photo.fileFolder+photo.fileName; 
      console.log('URL Completa: '+ urlCompleta); 

      $("#fotoRegistro").attr("src","file://"+urlCompleta+"?"+(new Date()).getTime()); 
     } 
    ); 
} 

在我objects.js文件:

var photo = { 
     fileFolder:null, 
     fileName:null, 
     takeAsync: function(fileFolder,fileName,onSuccess) { 
      navigator.device.capture.captureImage(
       function(photoFiles) { 
        var tempFullPath=photoFiles[0].fullPath; 
        tempFullPath=tempFullPath.substring(tempFullPath.indexOf("/")); 

        alert("New photo in: "+tempFullPath); 

        fileUtilities.moveAsync(tempFullPath,fileFolder,fileName, 
         function() { 
          photo.fileFolder=fileFolder; 
          photo.fileName=fileName; 
          if(onSuccess!=false) 
           onSuccess(); 
         }       
        ); 
       }, 
       function(error) { 
        var msgText = "Photo error: " + error.message + "(" + error.code + ")"; 
        alert(msgText); 
       } 
      ); 
     } 
}; 

而且fileUtilities:

var fileUtilities = { 
     moveAsync: function (sourceFullPath,destFolder,destName,onSuccess){ 
      var url="file://"+sourceFullPath; 
      var destFile=destFolder+destName; 
      var ft=new FileTransfer(); 
      ft.download(url,destFile, 
       function() { 
        window.resolveLocalFileSystemURL(url, 
          function(fileEntry) { 
         fileEntry.remove(onSuccess); 
          }, 
          function(error) { 
           alert("Source file NOT accesible; not removed"); 
          } 
        );   
       }, 
       function(error) { 
        alert('File not copied. '+'error.code: '+error.code+'\nerror.source: '+error.source+'\nerror.target: '+error.target+'\nerror.http_status: '+error.http_status); 
       } 
      ); 
     } 
}; 

感謝來自UPV /鵝湖莫氏硬度和G.P。