FileControl.java
3.93 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.sincere.file.control;
import com.sincere.file.model.FileInfo;
import com.sincere.file.model.result.Result;
import com.sincere.file.model.result.ResultFile;
import com.sincere.file.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
@RestController
@Api(tags = "文件管理")
@RequestMapping(value = "file/*")
public class FileControl {
Logger logger = LoggerFactory.getLogger(FileControl.class);
@Autowired
FileService fileService;
@PostMapping("fileUpload")
@ApiOperation("上传文件(重复文件会新增1)")
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();
}
@PostMapping("upload")
@ApiOperation("上传文件(重复文件会新增1)")
public Result upload(@RequestParam("imgFile") MultipartFile file, HttpServletRequest request) throws Exception {
String ossPath = request.getHeader("ossPath");//oss的二级目录
FileInfo fileInfo = fileService.upload(file, ossPath);
List<ResultFile> fileList = new ArrayList<>();
ResultFile resultFile = new ResultFile();
resultFile.setUrl(fileInfo.getUrl());
resultFile.setName(fileInfo.getName());
resultFile.setHref("");
fileList.add(resultFile);
return Result.genSuccessResult(fileList);
}
@PostMapping("fileUpload2")
@ApiOperation("上传文件(重复文件会新增1)")
public Result fileUpload2(@RequestParam("imgFile") MultipartFile file, HttpServletRequest request) throws Exception {
String ossPath = request.getHeader("ossPath");//oss的二级目录
FileInfo fileInfo = fileService.upload(file, ossPath);
return Result.genSuccess(fileInfo.getUrl());
}
@PostMapping("fileUpload1")
@ApiOperation("上传文件")
public String fileUpload1(@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);
System.out.println("fileName:" + fileName + "----ossPath:" + ossPath);
return true;
}
/*@RequestMapping(value = "getWord", method = RequestMethod.GET)
@ApiOperation("获取21世纪题目")
@ApiImplicitParams(
{@ApiImplicitParam(name = "url", value = "链接")}
)
public String getWord(@RequestParam("url") String url) {
RestTemplate restTemplate = new RestTemplate();
String content = restTemplate.getForObject(url, String.class, new HashMap<>());
// logger.error("json:{}", content);
JSONObject jsonObject = JSON.parseObject(content);
JSONObject data = jsonObject.getJSONObject("data");
JSONArray questions = data.getJSONArray("questions");
String wordPath = PoiUtils.createWord(questions);
// QuestionDataModel questionDataModel = JSON.parseObject(content, QuestionDataModel.class);
// logger.error("questionDataModel:{}", questionDataModel);
return fileService.uploadLocalFile(new File(wordPath), "test");
}*/
}