Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Created April 16, 2012 13:05
Show Gist options
  • Save joshdholtz/2398665 to your computer and use it in GitHub Desktop.
Save joshdholtz/2398665 to your computer and use it in GitHub Desktop.
Protocol Multipart Entity Snippet
// Creates the boundary for the multipart, the content type with the boundary, and the entity
String boundary = "---------------------------14737809831466499882746641449";
String contentType = "multipart/form-data; boundary=" + boundary;
HttpEntity entity = new ProtocolMultipartEntity(boundary, new File("/some/path"));
// Creates the post request
HttpPost httpPostFileRequest = new HttpPost(route);
httpPostFileRequest.addHeader("Content-Type", contentType);
httpPostFileRequest.setEntity(entity);
// Does the work
AbstractHttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpUriRequest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment