123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package com.diagbot.web;
- import com.diagbot.dto.FileDTO;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.facade.UploadFacade;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- @RestController
- @Api(value = "文件上传API", tags = { "文件上传API" })
- @RequestMapping(value = "/file_prec")
- @SuppressWarnings("unchecked")
- public class UploadController {
- @Autowired
- private UploadFacade uploadFacade;
- @ApiOperation(value = "文件上传")
- @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
- @PostMapping(value = "/uploadImage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- public RespDTO<FileDTO> singleFileUpload(@RequestParam("upfile") MultipartFile file) {
- FileDTO data = uploadFacade.singleFileUpload(file);
- if (data.getState().equals("FAILURE")) {
- return RespDTO.onError(data.getInfo());
- } else {
- return RespDTO.onSuc(data);
- }
- }
- @PostMapping("/deleteRemoteFile")
- @ApiOperation(value = "文件删除")
- public RespDTO<FileDTO> deleteRemoteFile(@RequestParam("path") String path) {
- FileDTO data = uploadFacade.deleteRemoteFile(path);
- if (data.getState().equals("FAILURE")) {
- return RespDTO.onError(data.getInfo());
- } else {
- return RespDTO.onSuc(data);
- }
- }
- }
|