I want to write Java application that will upload a file to the Apache server with PHP. The Java code uses Jakarta HttpClient library version 4.0 beta2:
impo
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).
org.apache.httpcomponents
httpmime
4.3.1