修改上传文件配置
This commit is contained in:
parent
f0925d2ed3
commit
f8a32a672f
@ -21,17 +21,22 @@ import java.util.HashMap;
|
||||
public class UploadController {
|
||||
@Value("${upload.path}")
|
||||
private String path;
|
||||
|
||||
@Value("${upload.url}")
|
||||
private String uploadUrl;
|
||||
@PostMapping()
|
||||
public Result upload(HttpServletRequest request,MultipartFile file) throws IOException {
|
||||
public Result upload(MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
return new Result().error("文件不能为空!");
|
||||
}
|
||||
//把文件的内容存储到本地磁盘上
|
||||
String originFileName = file.getOriginalFilename();
|
||||
file.transferTo(new File(path +"/"+ originFileName));
|
||||
String url = "http://localhost:18081/upload/" + originFileName;
|
||||
String url = uploadUrl + originFileName;
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
map.put("url",url);
|
||||
return new Result<>().ok(url);
|
||||
|
||||
map.put("path",url);
|
||||
map.put("absolute","upload/" + originFileName);
|
||||
return new Result<>().ok(map);
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,4 @@ spring:
|
||||
static-locations: "file:F:/upload/"
|
||||
upload:
|
||||
path: F:\upload
|
||||
url: https://bs.oss.xunyingcloud.cn/upload/movies/
|
||||
url: https://localhost:10081/upload/
|
||||
|
Loading…
Reference in New Issue
Block a user