Page 1 of 1

Send image with command "post"

Posted: Mon May 25, 2015 11:11 am
by dmeier
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?"

Re: Send image with command "post"

Posted: Mon May 25, 2015 1:41 pm
by MaxV
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".

Re: Send image with command "post"

Posted: Fri Jun 12, 2015 4:38 pm
by dmeier
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

Re: Send image with command "post"

Posted: Sun Jun 14, 2015 10:59 pm
by MaxV
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.