zoukankan      html  css  js  c++  java
  • 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/

    问题解决


  • 相关阅读:
    Codeforces Round #296 (Div. 2B. Error Correct System
    实验十二 图的建立与遍历
    1561: (More) Multiplication
    1562: Fun House
    hdu 2203 亲和串
    hdu 3549Flow Problem
    poj 2182 Lost Cows
    poj 3468A Simple Problem with Integers
    hdu1698 Just a Hook
    栈和队列的面试题Java实现
  • 原文地址:https://www.cnblogs.com/liw66/p/9987338.html
Copyright © 2011-2022 走看看