文件上传下载后端代码
- Upload 工具类:
@Component
@ConfigurationProperties("upload")
public class Upload {
private Logger log = LoggerFactory.getLogger(Upload.class);
// 获取存放位置
private Map<String, String> location;
// 单个文件大小
private String maxFileSize;
// 上次总文件大小
private String maxRequestSize;
// token验证密钥
private String secret;
public Map<String, String> getLocation() {
return location;
}
public void setLocation(Map<String, String> location) {
this.location = location;
}
public String getMaxFileSize() {
return maxFileSize;
}
public void setMaxFileSize(String maxFileSize) {
this.maxFileSize = maxFileSize;
}
public String getMaxRequestSize() {
return maxRequestSize;
}
public void setMaxRequestSize(String maxRequestSize) {
this.maxRequestSize = maxRequestSize;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String getBasePath() {
String location = "";
//system.getProperty获取系统属性名称
String os = System.getProperty("os.name");
//系统属性名称是否是以win为前缀
if(os.toLowerCase().startsWith("win")) {
location = this.getLocation().get("windows");
} else {
location = this.getLocation().get("linux");
}
return location;
}
/**
* @Description: TODO(初始化文件上传)
* @param
* @throws
*/
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
/