Uploading an image to server with phonegap (w/jquery ajax)

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Uploading an image to server with phonegap (w/jquery ajax)



I am trying to put together a small phonegap app to upload images to a collaboration site. I have looked over tutorial and API. So far I have the image captured but I am stuck on getting it to the server. I was hoping to use jquery for ajax it over. My jquery seems to stop the image capture btn working, when I take it out the btn works and captures an image. Is there another way other than jquery I can do this or I am just being a plonker and missing something? I am very new to phonegap.


$(document).ready(function()

function capturePhoto()
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, quality: 50 );




function onFail(message)
alert('Failed because: ' + message);


function onPhotoDataSuccess(imageData)

var url = 'http://www.creativetree.co/phonegapupload.php';
var params = image: imageData;
navigator.notification.alert('photo taken');


$.post(url, params, function(data)

// Display the selected image on send complete
$('#image').attr('src', 'data:image/jpeg;base64,' + params['image']);

);


);




2 Answers
2



The phonegap api has an example of this: http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileTransfer





would the PHP be similar to normal, I was using a $_POST earlier. What would I use to retrive the phonegap file transfer?
– ChrisSherwood
Mar 13 '12 at 14:09






it would be something like ft.upload(imageURI,creativetree.co/phonegapupload.php", win, fail, options);
– gmh04
Mar 13 '12 at 14:44



posting an image as base64 via ajax is fine, I have done it in apps several times.
However, the tricky part may be encoding/decoding and making sure the php processes it correctly. Make sure the PHP doesn't expect an actual image (binary).






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

dpAqofL sjosthyzFF6U5,xTCn ocpKE6 w87Kx,37y 5w8VT 65S695 HgTa dhGGVownySOv7A7X3 7O9Eas,ll U7QCdZxZ,fHHr1
4rL,MH9e MlzD pjIqBbZc ejghGiAUemQJ4s,WJOutjD gKRaG0pzftUSI FJe9Kc8OL

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3