package com.iailab.module.infra.controller.app.file;
|
|
import cn.hutool.core.io.IoUtil;
|
import com.iailab.framework.common.pojo.CommonResult;
|
import com.iailab.module.infra.controller.app.file.vo.AppFileUploadReqVO;
|
import com.iailab.module.infra.service.file.FileService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
|
import static com.iailab.framework.common.pojo.CommonResult.success;
|
|
@Tag(name = "用户 App - 文件存储")
|
@RestController
|
@RequestMapping("/infra/file")
|
@Validated
|
@Slf4j
|
public class AppFileController {
|
|
@Resource
|
private FileService fileService;
|
|
@PostMapping("/upload")
|
@Operation(summary = "上传文件")
|
public CommonResult<String> uploadFile(AppFileUploadReqVO uploadReqVO) throws Exception {
|
MultipartFile file = uploadReqVO.getFile();
|
String path = uploadReqVO.getPath();
|
return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())));
|
}
|
|
}
|