springboot上傳linux文件無法瀏覽,提示404錯誤
阿新 • • 發佈:2018-11-20
提示 iframe set wire figure path com nts 路徑
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錯誤