Friday 9 March 2012

Java Multipart Upload Code (Android Friendly)



This is a quick function to do a multipart upload of a file in android (and Java in general). It is adapted from Adrian Smith's code here: http://www.17od.com/2010/02/18/multipart-form-upload-on-android/.

 The differences are:
  1. This function will not try to read the file into a string (which imposes size restrictions).
  2. You can pass the content type of the file upon execution
  3. It returns whether or not it was successful and the HTTP response code.
  4. It does not read the response to the upload (if you want to add it back in, the code is in Adrian Smith's page above).