UploadController.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.diagbot.web;
  2. import com.diagbot.dto.FileDTO;
  3. import com.diagbot.dto.RespDTO;
  4. import com.diagbot.facade.UploadFacade;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.http.MediaType;
  9. import org.springframework.web.bind.annotation.CrossOrigin;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestMethod;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import org.springframework.web.multipart.MultipartFile;
  16. @RestController
  17. @Api(value = "文件上传API", tags = { "文件上传API" })
  18. @RequestMapping(value = "/file_prec")
  19. @SuppressWarnings("unchecked")
  20. public class UploadController {
  21. @Autowired
  22. private UploadFacade uploadFacade;
  23. @ApiOperation(value = "文件上传")
  24. @CrossOrigin(allowCredentials = "true", allowedHeaders = "*", methods = { RequestMethod.POST }, origins = "*")
  25. @PostMapping(value = "/uploadImage", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  26. public RespDTO<FileDTO> singleFileUpload(@RequestParam("upfile") MultipartFile file) {
  27. FileDTO data = uploadFacade.singleFileUpload(file);
  28. if (data.getState().equals("FAILURE")) {
  29. return RespDTO.onError(data.getInfo());
  30. } else {
  31. return RespDTO.onSuc(data);
  32. }
  33. }
  34. @PostMapping("/deleteRemoteFile")
  35. @ApiOperation(value = "文件删除")
  36. public RespDTO<FileDTO> deleteRemoteFile(@RequestParam("path") String path) {
  37. FileDTO data = uploadFacade.deleteRemoteFile(path);
  38. if (data.getState().equals("FAILURE")) {
  39. return RespDTO.onError(data.getInfo());
  40. } else {
  41. return RespDTO.onSuc(data);
  42. }
  43. }
  44. }