FileControl.java
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.sincere.file.control;
import com.sincere.file.model.FileInfo;
import com.sincere.file.service.FileService;
import com.sincere.file.utils.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@RestController
@Api(tags = "文件管理")
@RequestMapping(value = "file/*")
public class FileControl {
@Autowired
FileService fileService;
@PostMapping("fileUpload")
@ApiOperation("上传文件")
public String fileUpload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
String ossPath = request.getHeader("ossPath");//oss的二级目录
FileInfo fileInfo = fileService.upload(file, ossPath);
return fileInfo.getUrl();
}
@DeleteMapping("deleteFile/{fileName}")
@ApiOperation("删除文件")
public boolean deleteFile(@PathVariable String fileName,HttpServletRequest request){
String ossPath = request.getHeader("ossPath");//oss的二级目录
fileService.delete(fileName,ossPath);
return true;
}
}