一:代码报错
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。
换下即可成功。
本文解决了SpringBoot中文件上传时出现的临时目录缺失及文件类型转换错误的问题,提供了配置临时目录和调整文件类型的方法。
3230

被折叠的 条评论
为什么被折叠?



