springBoot文件上传后端配置
其他
2018-05-08 23:00:00
阅读次数: 3
1. 文件上传配置
@Configuration
public class FileUploadConfiguration {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("100MB"); // KB,MB
factory.setMaxRequestSize("100MB");
return factory.createMultipartConfig();
}
}
2. 控制器编写
@Controller
public class PicUploadController {
@RequestMapping("/file/upload")
@ResponseBody
public void update(@RequestParam("file") MultipartFile upfile) throws Exception {
String newName = System.currentTimeMillis()+".jpg";
InputStream is = upfile.getInputStream();
byte[] b = new byte[is.available()];
is.read(b);
FileOutputStream fos = new FileOutputStream(new File("E://"+newName));
fos.write(b);
fos.flush();
fos.close();
}
}
转载自blog.csdn.net/wangzhanzheng/article/details/78923490