commons-fileupload的新api使用,旧的使用,需要临时目录,新的api直接使用流的方式如下
// Check that we have a file upload request boolean isMultipart = ServletFileUpload.isMultipartContent(request); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); String name = item.getFieldName(); InputStream stream = item.openStream(); if (item.isFormField()) { System.out.println("Form field " + name + " with value " + Streams.asString(stream) + " detected."); } else { System.out.println("File field " + name + " with file name " + item.getName() + " detected."); // Process the input stream ... } }
时间: 2024-10-11 00:17:12