An update for those trying to use MultipartEntity
...
org.apache.http.entity.mime.MultipartEntity
is deprecated in 4.3.1.
You can use MultipartEntityBuilder
to create the HttpEntity
object.
File file = new File();
HttpEntity httpEntity = MultipartEntityBuilder.create()
.addBinaryBody("file", file, ContentType.create("image/jpeg"), file.getName())
.build();
For Maven users the class is available in the following dependency (almost the same as fervisa's answer, just with a later version).
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.1</version>
</dependency>