我在用,
org.apache.commons.fileupload.FileItem我想使用上传一个文件,
<form action="someAction" method="post" enctype="multipart/form-data">是否有方法将此文件/项转换为字节数组?目前,我已经在servlet中完成了,
List<FileItem> multiparts = upload.parseRequest(req);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
//Custom class need byte array as the file's content
CustomClass doc = new CustomClass();
//Need to set byte array value to this
doc.setValue(byte array);
item --> byte array????
}
}发布于 2017-09-11 05:01:37
来自javadoc (重点是我的):
从
FileUpload实例检索该类实例后(请参阅#parseRequest(javax.servlet.http.HttpServletRequest)),您可以立即使用得到()请求文件的所有内容,或者使用getInputStream()请求InputStream,然后在不试图将其加载到内存中的情况下处理该文件,这对于大型文件可能很有用。
https://stackoverflow.com/questions/46148441
复制相似问题