我正在使用 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);
感谢帮助!
谢谢, 苏雷兹
最佳答案
您可以使用以下 FileBody
设置文件名构造函数。
public FileBody(File file,
String filename,
String mimeType,
String charset)
关于java - 在 Apache HttpClient 中设置自定义文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9093237/