How to upload picture from Phonegap mobile app using AJAX?

12,008

OK, so the new 1.0.0 Phonegap documentation answer just this question. It can be found at: http://docs.phonegap.com/phonegap_file_file.md.html#FileTransfer

Share:
12,008
Frodik
Author by

Frodik

My favourite programming languages: PHP5, Javascript, jQuery SOreadytohelp

Updated on June 04, 2022

Comments

  • Frodik
    Frodik almost 2 years

    I have Phonegap mobile app and I am using Camera API to capture picture using this code:

    navigator.camera.getPicture(function(data){
      $.post('http://www.example.com', {data:data});
    }, function(msg){alert(msg);}, { quality: 20 });
    

    This would be OK, but there is need to set the quality option to some reasonable value depending on mobile device used. Some can handle values higher than 70, but low-end devices have troubles even with the value of 20. Phonegap documentation mentions these problem, that they are caused by memory needed since the whole picture is stored in Base64 string. Phonegap suggests to rather specify option destinationType: Camera.DestinationType.FILE_URI

    But as far as I understand this, I would get local filepath of the stored picture, which I would have to read it into one variable using FileReader API. And then $.postit again the same way as I am doing right now.

    To me, it seems, that if I would change the destinationType from Base64 to FILE_URI, I wouldn't gain anything and still have the same memory issues when reading it from the local file to variable and POSTing it.

    Is my thinking right ? Or am I missing something and there would be some advantage of using FILE_URI destionationType ? Or is there a better way how to upload taken picture ?