Best Android App InstaSquare Lite for full-size publication of photos in Instagram, Facebook, Twitter. Run the android application on PC. You can through the android emulator Droid4X.

HTTP Uploading in Android

Within the past year, the number of articles on doing this and that on Android has proliferated with a profound purpose.

However, given that the underlying Android SDK has gone through a variety of permutations, it's plausible that you've perused through a plurality of differing ways to do certain operations.

In particular the HTTP libraries seemed to have gone through a lot of changes. As of this writing SDK v1.0_R2, we ran into some difficulty sending multipart POSTs.

For our CSV exports, we wanted to be able to send arbitrarily sized files over HTTP. Granted the filesizes are managemable expecially after gzipping, however it cause me concern that the default method for doing HTTP posts required you to Stringifiy your entire object into the Keyvalue map for the POST parts.

This blog post, however, shows that multipart submissions can be handled more intelligently and in less of a memory hogging way by using the latest Apache HTTP libraries in your Android project:

 http://brainflush.wordpress.com/2008/10/17/talking-to-web-servers-via-http-in-android-10/

The result? A very straightforward HTTP posting logic that can accept arbitrarily large sized files. Since it only requires a handle to the Stream object, we're assuming that it does a more elegant job of reading over the file on sending. This code was verified to be able to send a 50 megabyte file with no problem. Carrier data charges, however will apply!

From our FormReviewer.java activity:

try {
	DefaultHttpClient httpclient = new DefaultHttpClient();
	File f = new File(filename);

	HttpPost httpost = new HttpPost("http://myremotehost:8080/upload/upload");
	MultipartEntity entity = new MultipartEntity();
	entity.addPart("myIdentifier", new StringBody("somevalue"));
	entity.addPart("myFile", new FileBody(f));
	httpost.setEntity(entity);

	HttpResponse response;
					
	response = httpclient.execute(httpost);

	Log.d("httpPost", "Login form get: " + response.getStatusLine());

	if (entity != null) {
		entity.consumeContent();
	}
	success = true;
} catch (Exception ex) {
	Log.d("FormReviewer", "Upload failed: " + ex.getMessage() + " Stacktrace: " + ex.getStackTrace());
	success = false;
} finally {
	mDebugHandler.post(mFinishUpload);
}