springboot上传linux文件无法浏览,提示404错误

Posted liw66

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot上传linux文件无法浏览,提示404错误相关的知识,希望对你有一定的参考价值。

1.配置文件地址置换
@Component
class WebConfigurer implements WebMvcConfigurer {
@Autowired
ConfigUtil bootdoConfig;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/files/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath());
}
}
2.配置工具类
@Component
@ConfigurationProperties(prefix="file")
public class ConfigUtil {
//上传路径
private String uploadPath;
  public String getUploadPath() {
  return uploadPath;
  }

  public void setUploadPath(String uploadPath) {
  this.uploadPath = uploadPath;
  }
}
3.js打开文件地址
var src = ‘/files/2018-11-16/*.png‘;
$("#viewDiv").empty();
var obj = $("<iframe src="+src+" width=‘99%‘ frameborder=‘0‘></iframe>");
if(document.documentElement.clientHeight != 0){
obj.height(document.documentElement.clientHeight)
}
$("#viewDiv").append(obj);

3.Application.yml里面配置的上传路径
file:
uploadPath: /www/server/*/uploaded_files

路径最后缺少一个/导致附件无法访问 改为
 uploadPath: /www/server/*/uploaded_files/

问题解决



































以上是关于springboot上传linux文件无法浏览,提示404错误的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot Web实现文件上传下载功能实例解析

SpringBoot Web实现文件上传下载功能实例解析

springboot zip文件上传无法解压

SpringBoot实现浏览器端大文件分块上传

SpringBoot实现浏览器端大文件分片上传

vcenter 6.5上传文件至存储卷:提示不信任证书,导致无法上传