NutzCN Logo
短点 现在做一个多文件上传功能,一直报一个错误,Stream closed,想问问是怎么回事?对nutz框架上传不太熟悉。求大神指教@wendal。
发布于 2400天前 作者 qq_03a9ff23 6230 次浏览 复制 上一个帖子 下一个帖子
标签:
 * 文件上传
	 */
	@POST
	/*@AdaptBy(type = UploadAdaptor.class,args = {"ioc:upload","${app.root}/WEB-INF/tmp"}) */
	@AdaptBy(type = UploadAdaptor.class,args = {"ioc:myUpload"})
	@At("/addfile")
	@Ok("jsp:/WEB-INF/admin/official/official-edit.jsp")
	public void uploadFile(@Param("Filedata")TempFile[] tempFile,HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//Item工厂
		DiskFileItemFactory factory = new DiskFileItemFactory();
		
		ServletFileUpload upload=new ServletFileUpload(factory);
		//设置内存缓冲区,超过后写入临时文件
		factory.setSizeThreshold(10240000);
		//设置临时文件存储位置
		String base = "f:/uploadFiles";//上传路径
		File file = new File(base);
		if(!file.exists())
			file.mkdirs();
		factory.setRepository(file);
	
		// 设置单个文件的最大上传值
		upload.setFileSizeMax(10002400000l);
		// 设置整个request的最大值
		upload.setSizeMax(10002400000l);
		upload.setHeaderEncoding("UTF-8");
		
		try {
			List<?> items = upload.parseRequest(request);//
			FileItem item = null;
			String fileName = null;
			for (int i = 0 ;i < items.size(); i++){
				item = (FileItem) items.get(i);
				fileName = base + File.separator + item.getName();
				// 保存文件
				if (!item.isFormField() && item.getName().length() > 0) {
					item.write(new File(fileName));//写入文件
				}
			}
		} catch (FileUploadException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

Caused by: java.io.IOException: Stream closed
	at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:312)
	at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
	at java.io.FilterInputStream.read(FilterInputStream.java:133)
	at org.apache.commons.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:134)
	at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:999)
	at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:903)
	at java.io.InputStream.read(InputStream.java:101)
	at org.apache.commons.fileupload.util.Streams.copy(Streams.java:100)
	at org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
	at org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:593)
	at org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:617)
	at org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:634)
	at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:1023)
	at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:1003)
	at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
	at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
	... 35 more

0 回复
添加回复
请先登陆
回到顶部