Multipart Posts

Most communication between a mobile app and the server can be handled with either a basic HTTP GET or HTTP POST operation. However, when media like images and video are involved, things become more complex. One way to transmit this data would be to create a special client/server protocol, and stream the content to the server. A much simpler implementation, however, would be to use a multipart HTTP POST.

A multipart post allows a browser (or a mobile app) to send complex data to the server via HTTP. From the documentation on the the W3 web site: "The content type 'application/x-www-form-urlencoded' is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type 'multipart/form-data' should be used for submitting forms that contain files, non-ASCII data, and binary data."

In the Futile Fishing application, users are able to take a picture of a caught fish. To get this data onto the server, I'll describe how to construct a multipart POST message and then send the contents to the server.

Building on the Prior Articles

The prior article titled Take a Picture, it'll Last Longer started the implementation of the catch details view / activity. The code was further enhanced in the article titled Pickin' and a Grinnin'. This article builds upon those prior articles, so portions of the code will not be (re)explained. If this causes difficulty, it may be advantageous to first read the prior articles.