Upload a photo from iphone with 64 encoding multi part form data
So, this wasn’t easy.
I Googled and Googled and got nowhere. Hopefully because of this post you didn’t look as hard.
Eventually I found this a post on the OLBTwitpicEngine source code. GREAT! I thought, until it didn’t work.
I had tried doing this on my own accord with a rails app; upload an iPhone photo to a rails server. I got the most bizarre error I have seen.
/!\ FAILSAFE /!\ Tue Mar 03 10:13:14 +1300 2009
Status: 500 Internal Server Error
bad content body
So I tried OLB’s code, and I got the same error! So I hacked away at my rails source code (the bit that processes a web request) so that it would spit out more details. I had no idea what the multipart form data was meant to look like, so how could I make sure it was right!
Eventually after a day of trial and error I figured out how the form data is meant to look like, and I got it working. Turns out the two new line characters at the beginning weren’t required. So you can go over to lingonikorgsource.wordpress.com and get yourself a copy of the code, then remove the first two new line chars and make it look like thusly
I would attach my code but I have hacked it to shreads and made it work how I need it. You will notice that their code makes use of threading, which I mention in my last post. Look how it’s done and you can put this photo upload with the previously mentioned post’s loading screen (which is exactly what I have done).
I will post about threading, but I will only be analysising how the above source code works and reporting from there. I could try some concurrency things as a couple experiments I suppose.. Concurrency is fun, isn’t it!! Say yes.