-
Notifications
You must be signed in to change notification settings - Fork 65
FileUpload OutOfDirectMemoryError #12
Copy link
Copy link
Open
Description
当我在上传大文件的时候会发生OOM
下面是文件上传代码:
`
@RequestMapping(value = "/stream-upload-test")
public ResponseEntity<String> upload(HttpServletRequest request, HttpServletResponse response)
throws IOException, FileUploadException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
Map<String, String> params = new HashMap<>();
InputStream is = null;
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
if (!item.isFormField()) {
is = item.openStream();
try {
int i = 0;
byte bb [] = new byte[4096];
while((i = is.read(bb)) != -1){
System.out.println(Arrays.toString(bb));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != is) {
is.close();
}
}
} else {
String fieldName = item.getFieldName();
String value = Streams.asString(item.openStream());
System.out.println(fieldName + " : " + value);
}
}
}
return new ResponseEntity<String>(HttpStatus.OK);
}
`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
