upload binary from ios with image data

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

upload binary from ios with image data

Post by maarten.koopmans » Mon Oct 24, 2011 10:50 pm

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

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Tue Oct 25, 2011 12:57 am

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
Attachments
Sample Pic.livecode.zip
(1.68 KiB) Downloaded 450 times

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Tue Oct 25, 2011 7:34 am

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.

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Wed Oct 26, 2011 11:23 pm

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!

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Sat Oct 29, 2011 12:28 pm

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

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Sun Oct 30, 2011 8:11 am

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

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Mon Oct 31, 2011 1:41 pm

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.

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Fri Nov 04, 2011 5:59 pm

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

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Fri Nov 04, 2011 6:18 pm

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

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Mon Nov 07, 2011 11:57 am

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?

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Mon Nov 07, 2011 3:42 pm

Actually, I have not sen or heard of a working solution..... From anyone.

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Mon Nov 07, 2011 5:59 pm

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?

maarten.koopmans
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 20
Joined: Sun Dec 28, 2008 3:26 pm

Re: upload binary from ios with image data

Post by maarten.koopmans » Sun Nov 13, 2011 7:50 am

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....

Kaubs
Posts: 124
Joined: Wed Jun 29, 2011 3:55 am

Re: upload binary from ios with image data

Post by Kaubs » Tue Nov 15, 2011 6:55 pm

Have you tried to send the photo not using the base64encode?

Post Reply