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;
    }

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




  • 相关阅读:
    三种方式循环打印1-100的值
    线程中put(None)和主函数中put(None)的区别和用法
    进程、线程这篇博客,让你傻傻的一次就能记清楚
    单生产者进程和单消费者进程
    队列
    初始线程
    常见面试题之*args
    常见面试题之*args 和 **kwargs 的使用
    闭包函数之函数加括号和不加括号的意义
    仓鼠找sugar II
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4004832.html
Copyright © 2011-2022 走看看