I used this answer to upload a multipart
file and my gradle http dependencies is like this:
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'org.apache.httpcomponents:httpcore:4.4.5'
and as the answer said, Java code is like this:
private void upload() {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPostHC4 uploadFile = new HttpPostHC4("...");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("field1", "yes", ContentType.TEXT_PLAIN);
// This attaches the file to the POST:
File f = new File("[/path/to/upload]");
builder.addBinaryBody(
"file",
new FileInputStream(f),
ContentType.APPLICATION_OCTET_STREAM,
f.getName()
);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response = httpClient.execute(uploadFile); //Error
HttpEntity responseEntity = response.getEntity();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
this problem is 'httpClient.execute(uploadFile);' does not accept uploadFile
as parameter!
How can I fix it?