Here's an example of MultipartEntityBuilder in action:
public static void postFile(String fileName) throws Exception {
// Based on:
http://stackoverflow.com/questions/2017414/post-multipart-request-with-android-sdk
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(SERVER + "uploadFile");
MultipartEntityBuilder multipartEntity =
MultipartEntityBuilder.create();
multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("file", new FileBody(new File(fileName)));
post.setEntity(multipartEntity.build());
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
// response.getStatusLine(); // CONSIDER Detect server complaints
entity.consumeContent();
client.getConnectionManager().shutdown();
} // FIXME Hook up a progress bar!
How do I add a progress bar? Should I extend the FileBody class,
override its getInputStream(), and return an input stream with an
overridden .write that counts the bytes & sends View commands. (I'm
inside Android, if that helps...)
--
Phlip
http://c2.com/cgi/wiki?ZeekLand
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]