springmvc 中将MultipartFile转为file,springboot 注入CommonsMultipartResolver
第一种方法: MultipartFile file = xxx;
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem(); File f = fi.getStoreLocation(); 会在项目的根目录的临时文件夹下生成一个文件; 第二种方法: transferTo(File dest); 会在项目中生成一个新文件; 第三种方法: File f = (File) xxx 强转即可。前提是要配置multipartResolver,要不然会报类型转换失败的异常。 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean>
没试过;
第四种方法:
Workbook wb = Workbook.getWorkbook(xxx .getInputStream());
转换为输入流,直接读取;
第五种方法:
byte[] buffer = myfile.getBytes();
先转换为字节数组,没试过;
//显示声明CommonsMultipartResolver为mutipartResolver
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
resolver.setResolveLazily(true);//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setMaxInMemorySize(40960);
resolver.setMaxUploadSize(50*1024*1024);//上传文件大小 50M 50*1024*1024
return resolver;
}
springmvc 中将MultipartFile转为file,springboot 注入CommonsMultipartResolver的更多相关文章
- SpringMVC 上传文件 MultipartFile 转为 File
在使用 SpringMVC 上传文件时,接收到的文件格式为 MultipartFile,但是在很多场景下使用都需要File格式的文件,记录下以便日后使用. 以下mFile为MultipartFile文 ...
- Springmvc 上传文件MultipartFile 转File
转自:http://blog.csdn.net/boneix/article/details/51303207 业务场景:ssm框架 上传文件到应用服务器过程中要传到专有的文件服务器并返回url进行其 ...
- springmvc文件上传 参数为MultipartFile 转换为File
package cn.com.mcd.controller;import java.io.File;import java.io.IOException;import java.io.Serializ ...
- SpringMVC 使用MultipartFile实现文件上传(转)
http://blog.csdn.net/kouwoo/article/details/40507565 一.配置文件:SpringMVC 用的是 的MultipartFile来进行文件上传 所以我们 ...
- pandas中将timestamp转为datetime
参考自:http://stackoverflow.com/questions/35312981/using-pandas-to-datetime-with-timestamps 在pandas Dat ...
- Opencv中将CvMat转为IplImage
Opencv中将CvMat转为IplImage,并在内存获得起头指针,而不用cvSaveImage(),贴上代码 IplImage * imgg = NULL; imgg = cvCreateImag ...
- SpringMVC Web项目升级为Springboot项目(二)
一.访问原项目地址,报404错误 由于原项目地址启动路径为http://localhost:8080/xxx Spring boot默认启动路径为http://localhost:8080/ 所以需要 ...
- [转]spring MultipartFile 转 File
原文地址:https://www.jianshu.com/p/6cf99d39e170 File.createTempFile(String prefix, String suffix); 创建一个临 ...
- MultipartFile 转换为File
选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 . MultipartFile multipartFile; File fil ...
随机推荐
- Web 常用
System.Web.Hosting.HostingEnvironment.MapPath(); HttpUtility.UrlEncode();
- 直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章
直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章_e-works数字化企业网 http://articles.e-works.net.cn/Component/Article ...
- C语言指针与指向指针的指针
#include <stdio.h> #include <string.h> int main() { char a[]="hello world"; ch ...
- Tensorflow MNIST浅层神经网络的解释和答复
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51416540 看到之前的一篇博文:深入 ...
- hdu 4950
#include<stdio.h> int main(){ __int64 h,a,b,k,j=0; while(scanf("%I64d%I64d%I64d%I64d" ...
- 记一次ruby的安装
1,下载rubyinstall 安装包及devkit包 登陆网站 :http://rubyinstaller.org/downloads/ 安装rubyinstall包时添加到环境变量 2,安装完in ...
- Unique Paths I,II
题目来自于:https://leetcode.com/problems/unique-paths/ :https://leetcode.com/problems/unique-paths-ii/ A ...
- mysql高可用架构方案之中的一个(keepalived+主主双活)
Mysql双主双活+keepalived实现高可用 文件夹 1.前言... 4 2.方案... 4 2.1.环境及软件... 4 2.2.IP规划... 4 2.3.架构图... ...
- codeforces 437D The Child and Zoo
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- selenium使用chrome抓取自动消失弹框的方法
selenium使用chrome抓取自动消失弹框的方法 转:https://blog.csdn.net/kennin19840715/article/details/76512394