Tuesday, November 11, 2014

Uploading to Google Cloud Storage from iOS app

I am using Google appengine for one of my iOS app (IntoMovies: Goodreads for movies and a community for movie and TV show fans - ) and also Google cloud storage to store images uploaded from the app. And, It took me a bit of head scratching to upload photos from iOS directly to google cloud storage. First, I didn't want to use google's iOS library which I think is not very clean and has way more code than it's really needed for simple use case. So i followed few web based samples and got the uploads working.

So, I am directly jumping to some code. I am assuming that you have google app engine project created and Google Cloud Storage is enabled in console's APIs & auth section.

1. Create a bucket in Cloud Storage section of your project's console

2. Create upload servlet or controller in appengine server that does 2 things:

    a) GET request handler that uses appengine's blobstore service to create the upload URL based
        on  bucket name and other   options and return to the client app.

    b)  POST request handler which is basically a callback from google cloud storage once image
         is uploaded to cloud store.

Here's the code for our Upload servlet,

3. Now the fun part, iOS client. Here I have a single method uploadImage that first gets the upload URL and uploads image data to that URL using multipart upload.
Here's the client code

 
One thing to note here is the form data that we pass in such as 'name' and 'filename' these should match the param names that you read in our POST request handler. Also, we are using blobstore to upload images to google cloud storage that way we are not limited by timeout limit on appengine instances. Though, we might need to have a cron job to remove keys from blob store.

Hope this helps!! Feel free to ask questions!

Friday, May 28, 2010

HTML 5 WebSocket API presentation

Good presentation slides by David Lindkvist via slideshare.com

Saturday, May 22, 2010

jWebSocket Step-By-Step

Just now i wrote a first part of the series of jWebSocket tutorials or articles that will try to write to cover everything about jWebSocket from the source.
http://blog.jwebsocket.org/2010/05/22/jwebsocket-step-by-step-part-1/

Saturday, May 1, 2010

invokedynamic on JDK7

Looks like JDK7 as per Oracle could be the next release of Java Platform. One of the most interesting addition seems to be the addition of new bytecode operation for method invocation, which is 'invokedynamic'.

invokedynamic bytecode operation which works more like 'inovkeinterface' but without the need to specify the return type and the target type of the method being invoked. This will release the lot of pressure from the developers dynamic languages that runs on JVM. Now They don't have to generate the bytecodes as per statically typed JVM because bytecode has been designed exclusively for statically typed languages, especially in its treatment of method invocation.

invokedynamic bytecode will use a linkage mechanism provided by class MethodHandle in the pacakage java.dyn, that contains the classes associated with dynamic language support in the Java platform.