开发者

How to upload picture from Phonegap mobile app using AJAX?

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开发者_StackOverflow upload taken picture ?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜