feat(icon_manage): 封装图标上传接口(不鉴权)
This commit is contained in:
parent
8accefb74c
commit
9d2e3067fc
@ -0,0 +1,69 @@
|
||||
package cn.axzo.oss.client.icon.controller;
|
||||
|
||||
import cn.axzo.oss.client.vo.FileInformationVo;
|
||||
import cn.axzo.oss.common.exception.BizException;
|
||||
import cn.axzo.oss.common.utils.BeanConvertUtil;
|
||||
import cn.axzo.oss.manager.api.dto.request.ServerFileUploadDto;
|
||||
import cn.axzo.oss.manager.api.dto.response.FileInformationResponse;
|
||||
import cn.axzo.oss.service.api.FileService;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import lombok.SneakyThrows;
|
||||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.axzo.oss.common.enums.CodeEnum.FILE_NAME_TOO_LONG;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
||||
|
||||
/**
|
||||
* 图标上传管理
|
||||
*
|
||||
* @author chenwenjian
|
||||
* @version 1.0
|
||||
* @date 2023/12/26 10:01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/icon")
|
||||
public class IconFileUploadController {
|
||||
|
||||
private static int FILE_NAME_MAX_LENGTH = 128;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
/**
|
||||
* 图标上传管理
|
||||
*
|
||||
* @param appCode 应用码 (oss提供) 此处使用app
|
||||
* @param bizScene 业务场景 (在oss服务中配置) 此处使用app
|
||||
* @param serviceName 调用方服务名 此处使用web
|
||||
* @param file 文件
|
||||
* @return {@link FileInformationVo}
|
||||
*/
|
||||
@PostMapping(value = "/fileUpload", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
@CrossOrigin
|
||||
@SneakyThrows
|
||||
public CommonResponse<FileInformationVo> uploadV2(@Valid @RequestParam("appCode") String appCode,
|
||||
@Valid @RequestParam("bizScene") String bizScene,
|
||||
@Valid @RequestParam("serviceName") String serviceName,
|
||||
@Valid @RequestPart MultipartFile file) {
|
||||
|
||||
String filename = file.getOriginalFilename();
|
||||
BizException.error(filename.length() < FILE_NAME_MAX_LENGTH, FILE_NAME_TOO_LONG);
|
||||
ServerFileUploadDto fileUploadDto = ServerFileUploadDto.builder()
|
||||
.appCode(appCode)
|
||||
.bizScene(bizScene)
|
||||
.fileName(filename)
|
||||
.fileContent(file.getBytes())
|
||||
.build();
|
||||
FileInformationResponse response = fileService.uploadV2(serviceName, fileUploadDto, null);
|
||||
FileInformationVo result = BeanConvertUtil.copyBean(response, FileInformationVo.class);
|
||||
return CommonResponse.success(result);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user