码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-11-20 11:26:12      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:404错误   ddr   try   spring   end   loaded   private   var   com   

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错误

标签:404错误   ddr   try   spring   end   loaded   private   var   com   

原文地址:https://www.cnblogs.com/liw66/p/9987338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!