I saw many questions about how to upload Images to a Server...but no Tutorial how to do it. Here is how I did it using JQuery and Python.
Follow this tutorial iPhone: Camera API
Now replace the success function with the following:
function getPicture_Success(imageData)
{
var feedURL = APIPATH + "photos/iphone-upload/";
$.post(feedURL, {imageData:imageData}, function(data){
});
}
In Python (Django):
def iphone_upload(request):
import base64
data = base64.b64decode(request.POST.get("imageData"))
fileout = "/var/www/test.jpg"
f1 = open(fileout,'wb+')
f1.write(data)
f1.close()
I hope this helps. I am just getting started with Phonegap (thnx for this great Project ;) ) and will be posting other tutorials as I go along. Follow me on twitter: http://www.twitter.com/scalar
Comments (3)
Mohamed Fouad said
at 1:22 pm on May 14, 2010
here is in php
<?php
$fp = fopen('data.txt', 'w');
fwrite($fp, $_POST['imageData']);
fclose($fp);
?>
Jeroen van Wissen said
at 3:38 am on Jun 15, 2010
I found out when testing with selecting an image and uploading it to a server, that a lot of EXIF data is lost from the JPEG file.
Including the Geolocation data in the EXIF headers is lost....
Is there any work around / fix to prevent this ?
Gavin Cooper said
at 5:37 am on Jun 15, 2010
Another image processing technique, requires GD lib 1.6+
// For some reason during the transport spaces get added instead of +
$data = str_replace(" ", "+", $_POST['photo']);
$data = base64_decode($data);
$img = imagecreatefromstring($data);
if ($img !== false) {
imagejpeg($img, UPLOADS.'img-'.date("r").'.'.time().'.jpg');
imagedestroy($img);
}
You don't have permission to comment on this page.