Commit 89a4775c69e52c5e2049513e4054d7d1103c8412
1 parent
b7125c31
Exists in
master
wangEditor文件上传接口提交
Showing
3 changed files
with
84 additions
and
18 deletions
Show diff stats
cloud/fIle-center/src/main/java/com/sincere/file/control/FileControl.java
| 1 | package com.sincere.file.control; | 1 | package com.sincere.file.control; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | -import com.alibaba.fastjson.JSONArray; | ||
| 5 | -import com.alibaba.fastjson.JSONObject; | ||
| 6 | -import com.alibaba.fastjson.serializer.SerializerFeature; | ||
| 7 | -import com.alibaba.fastjson.serializer.ValueFilter; | ||
| 8 | import com.sincere.file.model.FileInfo; | 3 | import com.sincere.file.model.FileInfo; |
| 9 | -import com.sincere.file.model.question.QuestionDataModel; | 4 | +import com.sincere.file.model.result.Result; |
| 5 | +import com.sincere.file.model.result.ResultFile; | ||
| 10 | import com.sincere.file.service.FileService; | 6 | import com.sincere.file.service.FileService; |
| 11 | -import com.sincere.file.utils.FileUtil; | ||
| 12 | -import com.sincere.file.utils.PoiUtils; | ||
| 13 | import io.swagger.annotations.Api; | 7 | import io.swagger.annotations.Api; |
| 14 | -import io.swagger.annotations.ApiImplicitParam; | ||
| 15 | -import io.swagger.annotations.ApiImplicitParams; | ||
| 16 | import io.swagger.annotations.ApiOperation; | 8 | import io.swagger.annotations.ApiOperation; |
| 17 | -import org.apache.poi.xwpf.usermodel.Document; | ||
| 18 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
| 19 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
| 20 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | -import org.springframework.boot.configurationprocessor.json.JSONException; | ||
| 22 | -import org.springframework.util.StringUtils; | ||
| 23 | import org.springframework.web.bind.annotation.*; | 12 | import org.springframework.web.bind.annotation.*; |
| 24 | -import org.springframework.web.client.RestTemplate; | ||
| 25 | import org.springframework.web.multipart.MultipartFile; | 13 | import org.springframework.web.multipart.MultipartFile; |
| 26 | 14 | ||
| 27 | import javax.servlet.http.HttpServletRequest; | 15 | import javax.servlet.http.HttpServletRequest; |
| 28 | -import java.io.File; | ||
| 29 | -import java.text.SimpleDateFormat; | ||
| 30 | import java.util.ArrayList; | 16 | import java.util.ArrayList; |
| 31 | -import java.util.Date; | ||
| 32 | -import java.util.HashMap; | ||
| 33 | import java.util.List; | 17 | import java.util.List; |
| 34 | 18 | ||
| 35 | @RestController | 19 | @RestController |
| @@ -54,6 +38,23 @@ public class FileControl { | @@ -54,6 +38,23 @@ public class FileControl { | ||
| 54 | 38 | ||
| 55 | } | 39 | } |
| 56 | 40 | ||
| 41 | + @PostMapping("upload") | ||
| 42 | + @ApiOperation("上传文件(重复文件会新增1)") | ||
| 43 | + public Result upload(@RequestParam("imgFile") MultipartFile file, HttpServletRequest request) throws Exception { | ||
| 44 | + | ||
| 45 | + String ossPath = request.getHeader("ossPath");//oss的二级目录 | ||
| 46 | + | ||
| 47 | + FileInfo fileInfo = fileService.upload(file, ossPath); | ||
| 48 | + List<ResultFile> fileList = new ArrayList<>(); | ||
| 49 | + ResultFile resultFile = new ResultFile(); | ||
| 50 | + resultFile.setUrl(fileInfo.getUrl()); | ||
| 51 | + resultFile.setName(fileInfo.getName()); | ||
| 52 | + resultFile.setHref(""); | ||
| 53 | + fileList.add(resultFile); | ||
| 54 | + return Result.genSuccessResult(fileList); | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + | ||
| 57 | 58 | ||
| 58 | @PostMapping("fileUpload1") | 59 | @PostMapping("fileUpload1") |
| 59 | @ApiOperation("上传文件") | 60 | @ApiOperation("上传文件") |
cloud/fIle-center/src/main/java/com/sincere/file/model/result/Result.java
0 → 100644
| @@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
| 1 | +package com.sincere.file.model.result; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created with IntelliJ IDEA. | ||
| 5 | + * | ||
| 6 | + * @Auther: xuquan | ||
| 7 | + * @Date: 2021/08/24 14:29 | ||
| 8 | + * @Description: 统一API响应结果封装 | ||
| 9 | + */ | ||
| 10 | +public class Result<T> { | ||
| 11 | + | ||
| 12 | + private int errno; | ||
| 13 | + private T data; | ||
| 14 | + | ||
| 15 | + public int getErrno() { | ||
| 16 | + return errno; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void setErrno(int errno) { | ||
| 20 | + this.errno = errno; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public T getData() { | ||
| 24 | + return data; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public Result<T> setCode(int errno) { | ||
| 28 | + this.errno =errno; | ||
| 29 | + return this; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + Result<T> setData(T data) { | ||
| 33 | + this.data = data; | ||
| 34 | + return this; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public static <T> Result<T> genSuccessResult(T data) { | ||
| 38 | + return new Result<T>() | ||
| 39 | + .setCode(0) | ||
| 40 | + .setData(data); | ||
| 41 | + } | ||
| 42 | +} |
cloud/fIle-center/src/main/java/com/sincere/file/model/result/ResultFile.java
0 → 100644
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +package com.sincere.file.model.result; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +import java.io.Serializable; | ||
| 6 | +import java.util.Date; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created with IntelliJ IDEA. | ||
| 10 | + * | ||
| 11 | + * @Auther: xuquan | ||
| 12 | + * @Date: 2021/08/24 14:29 | ||
| 13 | + * @Description: | ||
| 14 | + */ | ||
| 15 | +@Data | ||
| 16 | +public class ResultFile implements Serializable { | ||
| 17 | + | ||
| 18 | + private static final long serialVersionUID = -1L; | ||
| 19 | + private String href; | ||
| 20 | + private String name; | ||
| 21 | + private String url; | ||
| 22 | + | ||
| 23 | +} |