SpringBoot文件上传遇到的问题及解决方案

一:代码报错

Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [D:\\xyqbtest\\work\\Tomcat\\localhost\\xyqb\\nfs\\marvels-core-v2] is not valid

解决方案:

在springboot中上传文件没有临时目录所以会报以上错误,需要在application配置文件中指定临时文件目录

server.tomcat.basedir=文件路径

如果配置了spring.http.multipart.location=文件路径,需要加上该路径。

创建一个类,里面包含以下方法:

@Bean

public MultipartConfigElement multipartConfigElement() {

    MultipartConfigFactory factory = new MultipartConfigFactory();

    factory.setLocation("./tmp");

    return factory.createMultipartConfig();

}

重启即可生效。

 

二:代码报错

Failed to convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile': no matching editors or conversion strategy found

解决方案:

在springmvc中接收文件使用的是CommonsMultipartFile,springboot使用的是MultipartFile。

换下即可成功。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值