4 Replies Latest reply on Sep 20, 2017 4:49 AM by piero.alberto

    FileTransferError.FILE_NOT_FOUND_ERR with file transfer plugin

    piero.alberto Level 1

      In my phonegap app I take a picture with my camera and it works as expected.

       

      Then, I'd like to send it to my server. I see that sending the base64 encoded string is a bad practice and I figured the best solution is using the file transfer plugin.

       

      So, I added the plugin and I wrote this:

       

      function onPhotoURISuccess(imageURI) {
              try{
                  var url = "myserver/addPhoto";
                  alert(url);
                  var options = new FileUploadOptions();
                  options.chunkedMode = false;
                  options.fileKey = "recFile";
                  var imagefilename = imageURI;
                  options.fileName = imagefilename;
                  options.mimeType = "image/jpeg";
                  options.params = { "token": APP.TOKEN};
                  var ft = new FileTransfer();
                  alert(imagefilename);
                  ft.upload(imageURI, url, win, fail, options); 
              }
              catch (err) {
                  alert(err.message);
              }
          }
      

       

      In the last line in the try branch, I get the error FileTransferError.FILE_NOT_FOUND_ERR.

       

      In the alert before this line, I show in the alert the path (imagefilename variable). If I try to go manually in that path in my Android device, I can't find it. The path is file:///storage/emulated/0/Android/data/com.My.App/cache/1505307795417.jpg

       

      So, I tried to set the option

       

          saveToPhotoAlbum: true
      

       

      to check if the image is saved and I correctly see the photo in my album. I don't know why I get the error while sending it, can be the path wrong?

       

      I don't think the problem is server side, since I can't even see the request in the server log.

        • 1. Re: FileTransferError.FILE_NOT_FOUND_ERR with file transfer plugin
          piero.alberto Level 1

          The saved photo in my album has another path.

           

          The searched path is file:///storage/emulated/0/Android/data/com.My.App/cache/myImage.jpg

           

          The path of the saved image is /storage/emulated/0/Pictures/myImage.jpg

          • 2. Re: FileTransferError.FILE_NOT_FOUND_ERR with file transfer plugin
            piero.alberto Level 1

            I tried both with FILE_URI and NATIVE_URI as destinationType in the camera.GetPicture method. In both case the picture is saved, but also in both case I get the file not found error while trying to send it.

             

            The function to take the picture is:

             

            function getImage() {

                    // Retrieve image file location from specified source

                    navigator.camera.getPicture(onPhotoURISuccess, onFail, {

                            quality: 10,

                            destinationType: navigator.camera.DestinationType.NATIVE_URI,

                            saveToPhotoAlbum: true,

                            //sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY

                        }

                    );

                }

            • 3. Re: FileTransferError.FILE_NOT_FOUND_ERR with file transfer plugin
              piero.alberto Level 1

              I have a log printing line code at the beginning of the called method in my WCF. This line is never executed, so I can think the problem is client side... by the way, can be the server side the problem?

              • 4. Re: FileTransferError.FILE_NOT_FOUND_ERR with file transfer plugin
                piero.alberto Level 1

                I also tried this, but the result is still the same (file not found):

                 

                    function onPhotoURISuccess(imageURI) {

                        var filepath;

                        window.resolveLocalFileSystemURL(imageURI, function success(fileEntry) {

                  

                            // Do something with the FileEntry object, like write to it, upload it, etc.

                            // writeFile(fileEntry, imageURI);

                            filepath = fileEntry.fullPath;

                            alert("got file: " + fileEntry.fullPath);

                            // displayFileData(fileEntry.nativeURL, "Native URL");

                  

                            try {

                                var url = "myUrl";

                                alert(url);

                                var options = new FileUploadOptions();

                                options.chunkedMode = false;

                                options.fileKey = "recFile";

                                var imagefilename = filepath;

                                options.fileName = imagefilename;

                                options.mimeType = "image/jpeg";

                                options.params = { "token": APP.TOKEN }; // if we need to send parameters to the server request

                                var ft = new FileTransfer();

                                alert(imagefilename);

                                alert(imageURI);

                  

                                ft.upload(filepath, url, win, fail, options);

                            }

                            catch (err) {

                                alert(err.message);

                            }

                  

                        }, function () {

                            // If don't get the FileEntry (which may happen when testing

                            // on some emulators), copy to a new FileEntry.

                            alert("file system fail");

                            createNewFileEntry(imgUri);

                  

                        });

                  

                  

                    }