How to set up dynamically Part in MultipartRequestEntity
Posted
by ee_vin
on Stack Overflow
See other posts from Stack Overflow
or by ee_vin
Published on 2010-06-15T13:51:22Z
Indexed on
2010/06/15
13:52 UTC
Read the original article
Hit count: 217
Hello,
I'm using commons-httpclient-3.1 inside my android application. And I would like to know if it possible to manipulate Part (org.apache.commons.httpclient.methods.multipart.Part
) dynamically? Essentially adding new FilePart and new StringPart at runtime before sending the request.
Every example I've found until now suppose that you know how many fields you are dealing with. Ex:
File f = new File("/path/fileToUpload.txt");
PostMethod filePost = new PostMethod("http://host/some_path");
Part[] parts = {
new StringPart("param_name", "value"),
new FilePart(f.getName(), f)
};
filePost.setRequestEntity(
new MultipartRequestEntity(parts, filePost.getParams())
);
HttpClient client = new HttpClient();
int status = client.executeMethod(filePost);
Android specific thread: http://groups.google.com/group/android-developers/browse_thread/thread/0f9e17bbaf50c5fc
Thank you
© Stack Overflow or respective owner