Page 1 of 1
upload binary from ios with image data
Posted: Mon Oct 24, 2011 10:50 pm
by maarten.koopmans
Hi,
I saw a post on the forums for photos only... has anybody ever:
- take a picture
- added some parameters (like its name or so)
and used post on iOS to get it to the webserver. If so, how?
Any clues greatly appreciated!
--Maarten
Re: upload binary from ios with image data
Posted: Tue Oct 25, 2011 12:57 am
by Kaubs
I have attached a stack that should do just what you want. Some params are set on preopencard and the camera function is invoked. The upload button won't go anywhere until configured however it does have the code I used to base64encode an image and then send it off to a url of your choice. Please note that using this method on the server side you will need to bese64decode the image. The reason I did this in the first place is that I was having problems with the image becoming web safe in transition and losing data thus creating a black image. Please let me know if this helps or if there are any other questions I might be able to help you out with.
Kaubs
Re: upload binary from ios with image data
Posted: Tue Oct 25, 2011 7:34 am
by maarten.koopmans
Thanks,
That's a lifesaver. Any reason to pick jpeg over PNG? Also have you ever added extra parameters (though that should be easy, just more &key=value in the post data).
Again, thanks a lot for your help.
Re: upload binary from ios with image data
Posted: Wed Oct 26, 2011 11:23 pm
by Kaubs
Sorry it took me so long to get back to you. The server I was working with wanted JPEG over PNG so I sent JPEG format. Ive not added extra params but it has to be a possibility. Glad it worked for you!
Re: upload binary from ios with image data
Posted: Sat Oct 29, 2011 12:28 pm
by maarten.koopmans
One more subtle question, which has to do with the base64 encoding. A base 64 encoded string needs to be a multiple of 4. It' what all other implementation seem to do as well (tested Scala (JVM) and REBOL (C underneath).
But if I test with a standalone file like this:
put "/Users/maartenkoopmans/Desktop/pw.jpg" into tFilename
put base64encode(url("binfile:" & tFilename)) into tImage
answer "file read and converted"
answer the length of tImage
I consistently get 7758 as length in Livecode, and 7652 in other implementaions (REBOL, Scala). The form has two bytes to much to be multiple of 4, and way more than the others, which are multiples of fours. So how do you display files on the webserver then?
I figured you must have solved this....
--Maarten
Re: upload binary from ios with image data
Posted: Sun Oct 30, 2011 8:11 am
by Kaubs
The php server that receives the data in my case runs a base64decode command. I hope this makes sense! Our PHP guy handled the decode on his end so I'm not entirely in tune with it. Sorry! I hope this clears things up a little for you! The reason I used a base64encode is essentially to pass the pic in a web safe manner. When I tried to do so without it spaces and special chars were cut from the image resulting in a black image on the server side.
-Kaubs
Re: upload binary from ios with image data
Posted: Mon Oct 31, 2011 1:41 pm
by maarten.koopmans
Can he tell me if he does any special processing and can you privately send me what he had to do?
I recall another post when you has the question, used PNG and mentioned that you had to replace "_" by "+" on the server.
Re: upload binary from ios with image data
Posted: Fri Nov 04, 2011 5:59 pm
by maarten.koopmans
Klaus,
I think you made a small error in the stack;
on mouseUp
export image "samplepic" to myimage as jpeg
put "&image=" & base64Encode (img "samplepic") into tpic
post tpic to url "
http://putyoururlhere.com"
answer "Congrats! You have uploaded a pic!"
end mouseUp
I think in the second line "samplepic" should read:
put "&image=" & base64Encode (myimage") into tpic
Right?
Thanks, Maarten
Re: upload binary from ios with image data
Posted: Fri Nov 04, 2011 6:18 pm
by Kaubs
I think you might be right, I'd have to test it out. However, I am kaubs, if klaus were helping you there wouldn't have been an error lol.
Kaubs
Re: upload binary from ios with image data
Posted: Mon Nov 07, 2011 11:57 am
by maarten.koopmans
There is more wrong - you use the Android function to make a photo for example.
Have you tested your stack before you send it here?
Re: upload binary from ios with image data
Posted: Mon Nov 07, 2011 3:42 pm
by maarten.koopmans
Actually, I have not sen or heard of a working solution..... From anyone.
Re: upload binary from ios with image data
Posted: Mon Nov 07, 2011 5:59 pm
by Kaubs
Interesting, Ill have to look at it again. Thats almost the exact stack I used to test submit photos which is currently in production. Unfortunately I don't have a test server to look at the result right now. What exactly is happening for you?
Re: upload binary from ios with image data
Posted: Sun Nov 13, 2011 7:50 am
by maarten.koopmans
All is going well (LC 5.0), iOS 5 iPhone4, but when I hist submit no data is being sent and the iPhone hangs. Replace the base64 encoded photo by text and I see my webservice receiving data....
Re: upload binary from ios with image data
Posted: Tue Nov 15, 2011 6:55 pm
by Kaubs
Have you tried to send the photo not using the base64encode?