springCloud+springMVC文件上传限制问题

  http:
    multipart:
      enabled: true   # 启用http上传处理
      max-file-size: 100MB # 设置单个文件的最大长度
      max-request-size: 100MB # 设置最大的请求文件的大小
      file-size-threshold: 1MB  # 当上传文件达到1MB的时候进行磁盘写入
      location: /  # 上传的临时目录

增加multpart限制说明

springCloud+springMVC文件上传限制问题_第1张图片
-------------------------------------------------------------------------------------

web端



	
		  
	



	

文件上传

文件描述:
请选择文件:
后台服务

package com.xxxx

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class UploadFileDemoController {

	
	/**
	 * 初始化方法,
	 * @param dc
	 * @return
	 */
	@RequestMapping({ "/uploadinit" })
	public String init() {
		return "/uploadFileDemo.html";
	}
	
	@RequestMapping(value="/upload")
	@ResponseBody
	public String retrieve(HttpServletRequest request,
			@RequestParam("description") String description,
            @RequestParam("file") MultipartFile file) {
		System.out.println("其他参数:"+description);
        //如果文件不为空,写入上传路径
        if(!file.isEmpty()) {
            //上传文件名
            String filename = file.getOriginalFilename();
            System.out.println(filename);
            try {
				InputStream in = file.getInputStream();

	            //测试存入本机 G 盘
	            File toFile = new File("G:\\",filename);
				FileOutputStream out = new FileOutputStream(toFile);
				
				byte[] b = new byte[1024];
				int a = 0;
				while((a = in.read(b))!=-1){
					out.write(b, 0, a);
				}
				out.flush();
				out.close();
				in.close();
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            return "success";
        } else {
            return "-1";
        }
	
	}
}






你可能感兴趣的:(springCloud,springMVC,学习笔记)