Send image with command "post"

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dmeier
Posts: 15
Joined: Mon May 25, 2015 10:52 am

Send image with command "post"

Post by dmeier » Mon May 25, 2015 11:11 am

Hi

I need to send a picture taken from Androids camera to a server where mysql is running. I can do this only through port 80/8080 (http). Therefore I think I need to submit my data with the post-command. I wrote a php script that acts as API. The API-PHP script receives the data and sends them to mysql.
This works fine with normal text variables, but not with images. As they are arrays I don't know how to send them with post.

Thanks a lot for help
David

That's what I am trying with livecode (Name, Vorname, Mail and Channel work fine but tFile is not being transmitted:

set the width of the templateImage to 295
set the height of the templateImage to 170
set the left of the templateimage to "20"
set the top of the templateimage to "50"
set the lockLoc of the templateImage to true
set the name of the templateImage to "camPict"
mobilePickPhoto "Camera"
export image "camPict" to tFile as jpeg
put "Name=Rene&Vorname=rafi&Mail=mymail&Channel=22&File=" & URLEncode(tFile) into tArgList
post tArgList to URL "myserver/api.php?"

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Send image with command "post"

Post by MaxV » Mon May 25, 2015 1:41 pm

You need to use base64Encode and specify what data you want to save. Your code send file path.
I would use this:
########CODE#######
mobilePickPhoto "Camera"
export image "camPict" to tFile as jpeg
put URL ("binfile:" & tFIle) into image_data
put base64Encode(image_data) into imagedata2
put urlencode("Name=Rene&Vorname=rafi&Mail=mymail&Channel=22&File=" & imagedata2) into tArgList
post tArgList to URL "myserver/api.php?"
#####END OF CODE#####

However if your image will be loadaed only by livecode, you can speedup using "the text of last image".
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

dmeier
Posts: 15
Joined: Mon May 25, 2015 10:52 am

Re: Send image with command "post"

Post by dmeier » Fri Jun 12, 2015 4:38 pm

Dear MaxV

sorry for my late reply I was very busy and had to do some other stuff than programming livecode! But many thanks for your reply, which helps a lot. It's the base64encoding that does the trick. I don't know why though.

cheers and kind regards

David

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Send image with command "post"

Post by MaxV » Sun Jun 14, 2015 10:59 pm

dmeier wrote: It's the base64encoding that does the trick. I don't know why though.
David,
the base64encoding transforms any nasty chars in a standard ASCII chars. Here is the magic. :lol: .
ASCII chars are standard and there aren't problem in transferring or interpreting them.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply