需要做一个app跟新功能,本来从ftp上可以访问到文件然后转成流的方式传到前端,但是前端以写好的功能不支持流;于是只能把文件保存到服务器然后使用这种方式进行
package com.cmiot.core.controller;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* app包绝对地址与虚拟地址映射
* 用于更新app
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//文件磁盘图片url 映射
//配置server虚拟路径,handler为前台访问的目录,locations为files相对应的本地路径
//win
registry.addResourceHandler("/downapp/**").addResourceLocations("file:///D:\\");
//linux
registry.addResourceHandler("/downapp/**").addResourceLocations("file:///down/");
}
}
前端使用localhost:8080/downapp/test.apk进行访问即可