Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update April 29th 2014:</strong></p> <p>My answer is kind of old by now and I guess you rather want to use some kind of high level library such as <a href="https://square.github.io/retrofit/">Retrofit</a>.</p> <hr> <p>Based on this blog I came up with the following solution: <a href="http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/">http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/</a></p> <p>You will have to download additional libraries to get <code>MultipartEntity</code> running!</p> <p>1) Download httpcomponents-client-4.1.zip from <a href="http://james.apache.org/download.cgi#Apache_Mime4J">http://james.apache.org/download.cgi#Apache_Mime4J</a> and add apache-mime4j-0.6.1.jar to your project.</p> <p>2) Download httpcomponents-client-4.1-bin.zip from <a href="http://hc.apache.org/downloads.cgi">http://hc.apache.org/downloads.cgi</a> and add httpclient-4.1.jar, httpcore-4.1.jar and httpmime-4.1.jar to your project.</p> <p>3) Use the example code below.</p> <pre><code>private DefaultHttpClient mHttpClient; public ServerCommunication() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); mHttpClient = new DefaultHttpClient(params); } public void uploadUserPhoto(File image) { try { HttpPost httppost = new HttpPost("some url"); MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart("Title", new StringBody("Title")); multipartEntity.addPart("Nick", new StringBody("Nick")); multipartEntity.addPart("Email", new StringBody("Email")); multipartEntity.addPart("Description", new StringBody(Settings.SHARE.TEXT)); multipartEntity.addPart("Image", new FileBody(image)); httppost.setEntity(multipartEntity); mHttpClient.execute(httppost, new PhotoUploadResponseHandler()); } catch (Exception e) { Log.e(ServerCommunication.class.getName(), e.getLocalizedMessage(), e); } } private class PhotoUploadResponseHandler implements ResponseHandler&lt;Object&gt; { @Override public Object handleResponse(HttpResponse response) throws ClientProtocolException, IOException { HttpEntity r_entity = response.getEntity(); String responseString = EntityUtils.toString(r_entity); Log.d("UPLOAD", responseString); return null; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload