zoukankan      html  css  js  c++  java
  • Spring的文件上传

    Spring在发现包括multipart的请求后,会使用MultipartResolver的实现bean处理文件上传操作,现有採用Servlet3的
    org.springframework.web.multipart.support.StandardServletMultipartResolver

     和採用commons-fileupload的

    org.springframework.web.multipart.commons.CommonsMultipartResolver

    处理文件的上传须要重写接口MultipartResolver的parseRequest方法。

    其涉及到的成员变量类型:

    public CommonsFileUploadSupport() {this.fileItemFactory = newFileItemFactory();
    <span style="white-space:pre">	</span>this.fileUpload = newFileUpload(getFileItemFactory());
    }
    protected DiskFileItemFactory newFileItemFactory() {
    	return new DiskFileItemFactory();
    }


    DiskFileItemFactory#createItem

    public FileItem createItem(String fieldName, String contentType,
    		boolean isFormField, String fileName) {
    	DiskFileItem result = new DiskFileItem(fieldName, contentType,
    			isFormField, fileName, sizeThreshold, repository);
    	FileCleaningTracker tracker = getFileCleaningTracker();
    	if (tracker != null) {
    		tracker.track(result.getTempFile(), this);
    	}
    	return result;
    }
    DiskFileItem#getOutputStream

    public OutputStream getOutputStream()
    	throws IOException {
    	if (dfos == null) {
    		File outputFile = getTempFile();
    		dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
    	}
    	return dfos;
    }

    其默认採用暂时文件保存上传内容,若超过指定的内存限制大小,则直接存储为暂时文件




  • 相关阅读:
    模块
    python运算符与表达式
    subShell与代码块
    参数展开与特殊字符
    变量和参数
    shelll Test
    Cypher查询语言--Neo4j 入门 (一)
    那些争议最大的编程观点
    大型网站架构不得不考虑的10个问题
    大型网站架构演变
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4004832.html
Copyright © 2011-2022 走看看