Search in sources :

Example 1 with FileConvertResultDTO

use of com.github.lybgeek.file.dto.FileConvertResultDTO in project springboot-learning by lyb-geek.

the class FileController method upload.

@PostMapping(value = "/upload")
@ResponseBody
public Result<String> upload(@RequestParam("file") MultipartFile file) throws IOException {
    Map<String, Object> params = new HashMap<>();
    params.put(FileConstant.FILE_PARAM_KEY, file.getBytes());
    String response = HttpClientUtil.INSTANCE.post(FileConstant.PREVIEW_REMOTE_URL, params, file.getOriginalFilename());
    FileConvertResultDTO fileConvertResultDTO = JSON.parseObject(response, FileConvertResultDTO.class);
    if (ObjectUtils.isNotEmpty(fileConvertResultDTO) && FileConstant.SUCCESS.equals(fileConvertResultDTO.getStatus())) {
        return new Result<String>().setData(fileConvertResultDTO.getTargetFileName());
    }
    throw new BizException("文件上传解析预览失败", 406);
}
Also used : HashMap(java.util.HashMap) BizException(com.github.lybgeek.common.exception.BizException) FileConvertResultDTO(com.github.lybgeek.file.dto.FileConvertResultDTO) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BizException (com.github.lybgeek.common.exception.BizException)1 FileConvertResultDTO (com.github.lybgeek.file.dto.FileConvertResultDTO)1 HashMap (java.util.HashMap)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1