1

I'm trying to implement a FileUpload function with PhoneGap. Used almost the code of the API example:

navigator.camera.getPicture(function(file) {
    l(file);

    var options = new FileUploadOptions();
    options.fileKey ="files";
    options.fileName = file.substr(file.lastIndexOf('/')+1);
    options.mimeType = "image/jpeg";

    var ft = new FileTransfer();
    ft.upload(file, path, function(o) {
        l('upload ok')
    }, function(error) {
        l('upload failed')
        l('code: '+error.code);
        l('source: '+error.source);
        l('target: '+error.target);
        l('http_status: '+error.http_status);
    }, options, true);
}, {
    quality: 75,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM
});

The media library is opened, I chose a file, the file path is showed and then the upload fails. The error object and all output is NULL so I cannot find out why. The post request is never executed on the server. Any ideas?

I'm using current PhoneGap with build service. I added this to config.xml:

<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />

By the way, it works on iOS.

Thanks for any help

quape
  • 726
  • 9
  • 21
  • In ft.upload(file, path, function(o) { l('upload ok') ADD: alert("file:"+file); alert("path:"+path); if they are null it is a asycronuous problem: http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call/14220323#14220323 – anotherBug May 14 '14 at 08:36
  • This part is the onSuccess block and isn't called, unfortunately. – quape May 14 '14 at 08:54
  • And before they are also null? var ft = new FileTransfer(); alert("file:"+file); alert("path:"+path); ft.upload(file, path, function(o) { / Is path php? – anotherBug May 14 '14 at 09:29
  • then output is `file: content://media/external/images/media/30981 path: https://host/upload.php` – quape May 14 '14 at 09:35
  • I think you need the phisical path not the uri. var ft = new FileTransfer(); alert(file.fullPath) ft.upload(file, path, function(o) { / The result is different? – anotherBug May 14 '14 at 09:55
  • Hm, `file` is a string, there is no `.fullPath`. I took the code from the API example, it's like there. – quape May 14 '14 at 11:46
  • http://stackoverflow.com/questions/13550523/get-picture-location-phonegap-camera – anotherBug May 14 '14 at 11:54
  • This returns /media/external/images/media/30981 ;) But no change, no request is done and upload() returns NULL :( – quape May 14 '14 at 12:06
  • Used `encodeURI(path)` ? – Manjesh V Jul 06 '14 at 15:02

0 Answers0