0

I seem to have run into a wall trying to upload photos to a server using Phonegap application and an ASP.net page in server side. I've checked my code several times and the person who has written the aspx service has checked things on their side. I'm using the filetransfer and file plugin and an application error occured when calling upload method with code 1. I am trying first of all to upload image in the server using a simple request AJAX and it works. But when using phonegap plugins, it doesn't work. here is my code:

function getImage() {
        navigator.camera.getPicture(uploadPhoto, function(message) {
            alert('get picture failed');
        }, {
            quality: 100,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
        });

    }

function uploadPhoto(imageURI) {
        alert("entrer dans uploadPhoto");
        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
        options.mimeType = "image/jpeg";
        console.log(options.fileName);
        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;
        options.chunkedMode = false;

        var ft = new FileTransfer();
        ft.upload(imageURI, "http://192.168.100.165/ProjetCourtageServerSide/DownloadDocumentSinistre.aspx", function(result){
            alert(JSON.stringify(result));
        }, function(error){
            alert(JSON.stringify(error));
        }, options);
    }
  • where `uploadPhoto(imageURI)` called? I don't see on your codes. – Metalik Jun 18 '18 at 11:19
  • Upload a Photo when you get an image from photolibrary, it is called in the success of getPicture. – Hamza Belheni Jun 18 '18 at 11:21
  • any console log errors? – Metalik Jun 18 '18 at 11:23
  • yes there is a console log error with code :1 and message : An application error occured on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely... This error does not specify the exact reason of the bug. – Hamza Belheni Jun 18 '18 at 11:29
  • Problem is related to server side. You should enable error codes on server side and debug it. I did not see any problems on your client code. – Metalik Jun 18 '18 at 11:30
  • I am trying first of all to upload image in the server using a simple request AJAX calling an ASP.net page and it works. But when using phonegap plugins, it doesn't work. – Hamza Belheni Jun 18 '18 at 11:32
  • Maybe CORS problem. https://stackoverflow.com/questions/37398695/cors-cordova-issues-with-access-control-allow-origin – Metalik Jun 18 '18 at 11:33
  • Maybe it's a navaigation whitelist resctriction, do you have `` in your config.xml ? – Djiggy Jun 18 '18 at 11:47
  • i have in my config.xml and i don't think is a CORS problem because it works when working with request AJAX that called an ASP.net page – Hamza Belheni Jun 18 '18 at 13:41

1 Answers1

0

i think your problem is asked in the wrong way, can u try and give more specifications about your real problem? and maybe try to hide your ip address and url to the service next time you post a question !

deepmore
  • 81
  • 1
  • 8
  • ok i will hide next time my ip address. But my problem is that i can't upload an image to my server using plugin phonegap application. – Hamza Belheni Jun 18 '18 at 13:53