0

I am using Phonegap 5.3.1 and Android 22. I am trying to use the Filetransfer api of phonegap to transfer the images to the remote server.

var options = new FileUploadOptions();          
options.fileKey="file";
options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
alert("The filename here is : " + imageData);

so here the imageData prints

content //com.android.providers.media.documents/document/image/image%3A53

and the further the below code

imageData.substr(imageData.lastIndexOf('/')+1);

does assign options.fileName = "image%3A53"

This is not the image name that I have on device. In my opinion this is causing an issue.

The javascript used to run the FileTransfer plugin says that the file is transferred successfully but I cannot find the file on the server(runing PHP).

The server response is as follows:

got response from server

  Array
  (
      [file] => Array
          (
              [name] => image%3A53
              [type] => image/jpeg
              [tmp_name] => /tmp/php8qjZXN
              [error] => 0
              [size] => 137490
          )
  )

Also few posts say: Phonegap android unable to upload image using fileTransfer

You can not use imageUri that you get from camera success callback in FileTransfer upload method, you have to first resolve uri as a filename like this:

navigator.camera.getPicture(function(imageURI){

      window.resolveLocalFileSystemURI(imageUri, function(fileEntry) {
            fileEntry.file(function(fileObj) {

                var fileName = fileObj.fullPath;

                //now use the fileName in your method
                //ft.upload(fileName ,serverURL + '/ajax.php?fname=appuploadspotimage'...);

            });
        });
});

Any help would be highly appreciated.

Community
  • 1
  • 1
user563101
  • 1,155
  • 2
  • 7
  • 5

1 Answers1

0

I found the answer to my question. The issue was not on the client side but was on the server side. I referred the below post: fileupload success, but no photos in the server (phonegap android)

The crux is "Have you checked your folder and script permissions? They both should have the same user/group. If you're running Apache,it would be something like apache:apache. From the cmd line you can run chown apache:apache upload.php then chown -R apache:apache php/"

The function move_upload_file([source],[destination]). The path to your images folder should be somewhere under your web site root directory. The uploaded files are moved from /tmp to your upload folder. That folder(and script doing the work) needs to be owned by apache.

I made the permissions as mentioned above and it worked. Thanks all for all your timely responses.

Community
  • 1
  • 1
user563101
  • 1,155
  • 2
  • 7
  • 5