1

I'm developing an Android application with PhoneGap, my problem is I want to take a picture and save in a specified folder, I read a lot of tutorial online but I cannot find the solution on my problem, now I take the picture and save it in the default folder.

here is my js file.

var pictureSource;   
var destinationType;
document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady() {
   pictureSource=navigator.camera.PictureSourceType;
   destinationType=navigator.camera.DestinationType;
}

function onPhotoDataSuccess(imageURI) {

   var smallImage = document.getElementById('smallImage');
   smallImage.style.display = 'block';
   smallImage.src = imageURI;
   movePic(imageURI);
}

function capturePhoto() {
   navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
   destinationType: destinationType.FILE_URI,
   saveToPhotoAlbum: true});
}

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

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

function resolveOnSuccess(entry){
   var d = new Date();
   var n = d.getTime();

   var newFileName = n + ".jpg";
   var myFolderApp = "Geofolder";

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

function successMove(entry) {
   sessionStorage.setItem('imagepath', entry.fullPath);

}

function resOnError(error) {
   alert(error.code); 
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
  • Possible duplicate of [Capturing and storing a picture taken with the Camera into a local database / PhoneGap / Cordova / iOS](http://stackoverflow.com/questions/10335563/capturing-and-storing-a-picture-taken-with-the-camera-into-a-local-database-ph) – lifeisfoo Jun 22 '16 at 13:00

1 Answers1

2

You have to get the directory entry.Try the following function.

function moveFile(fileUri) {
window.resolveLocalFileSystemURL(
      fileUri,
      function(fileEntry){
            window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory,
                function(dirEntry) {
                        fileEntry.moveTo(dirEntry, "fileName.jpg", function(entry){
                            alert("File moved.check internal memory");
                        },resOnError);
                    },
                    resOnError);
      },
      resOnError);}
Homen
  • 1,222
  • 1
  • 12
  • 16