在 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);
感谢帮助!
谢谢, 苏雷兹
I am using Apache HttpClient to upload a file through MultipartEntity, I need to upload the file with different filename.. Below is my code...
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);
Help Appreciated!
Thanks,
Surez
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下内容设置文件名
FileBody
构造函数。You can set file name with the following
FileBody
constructor.