Установка пользовательского имени файла в Apache HttpClient
Я использую Apache HttpClient для загрузки файла через MultipartEntity, мне нужно загрузить файл с другим именем файла. Ниже мой код...
FileBody uploadFilePart = new FileBody(binaryFile);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", uploadFilePart);
reqEntity.addPart("comment", comment);
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: " +
resEntity.getContentLength());
}
EntityUtils.consume(resEntity);
Помощь приветствуется!
Спасибо, Сюрез
1 ответ
Решение
Вы можете установить имя файла с помощью следующего FileBody
конструктор.
public FileBody(File file,
String filename,
String mimeType,
String charset)