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);

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

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

问题解决


posted @ 2018-11-20 10:16  liw66  阅读(1142)  评论(0编辑  收藏  举报