我收回了同事的节目。
他做了这个方法(这个程序允许在服务器上传文件):
protected String uploadFile(File inputFile, String uuidFile) throws IOException,
ClientProtocolException {
HttpPost post = new HttpPost(new StringBuilder()
.append("http://xxxxxxxxxxxxx/FileServlet/").append("/uploadFile")
.toString());
post.addHeader("UuidFile", uuidFile);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("file", new FileBody(inputFile));
HttpEntity httpEntity = builder.build();
post.setEntity(httpEntity);
CloseableHttpClient client = HttpClients.createDefault();
HttpResponse response = null;
try {
response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
Pattern p = Pattern.compile("File uploaded into (.*)</h2>");
String messageErreur = IOUtils.toString(response.getEntity().getContent());
System.out.println(messageErreur);
Matcher m = p.matcher(messageErreur);
if (m.find()) {
return m.group(1);
}
} else {
throw new RuntimeException(response.getStatusLine().getStatusCode() + ": " + new String(IOUtils.toByteArray(response.getEntity().getContent())));
}
return null;
} finally {
client.close();
}
}
控制台中的错误是
出现错误:请求因其大小而被拒绝 (68142301)超出配置的最大值(52428800)
但是我不知道如何增加上传文件的最大大小......
你有什么想法吗?
谢谢, 阿诺
答案 0 :(得分:1)
从现在开始解决错误检查web.xml以获取servlet中的以下配置。增加尺寸并检查。
<multipart-config>
<max-file-size>68142301</max-file-size>
<max-request-size>68142301</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
答案 1 :(得分:0)
它的功能,另一位同事给了项目方服务,它有
ServletFileUpload upload = new ServletFileUpload(factory);
// sets maximum size of upload file
upload.setFileSizeMax(MAX_FILE_SIZE);
// sets maximum size of request (include file + form data)
upload.setSizeMax(MAX_REQUEST_SIZE);
改变