feat: add upload file api
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.youlai.boot.app.controller;
|
||||
|
||||
import com.youlai.boot.app.model.vo.AppFileInfo;
|
||||
import com.youlai.boot.app.service.AppFileService;
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 文件控制层
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2022/10/16
|
||||
*/
|
||||
@Tag(name = "10.文件接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/app/files")
|
||||
@RequiredArgsConstructor
|
||||
public class AppFileController {
|
||||
|
||||
private final AppFileService fileService;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "文件上传")
|
||||
public Result<AppFileInfo> uploadFile(
|
||||
@Parameter(
|
||||
name = "file",
|
||||
description = "表单文件对象",
|
||||
required = true,
|
||||
in = ParameterIn.DEFAULT,
|
||||
schema = @Schema(name = "file", format = "binary")
|
||||
)
|
||||
@RequestPart(value = "file") MultipartFile file
|
||||
) {
|
||||
Assert.isTrue(!file.isEmpty(), "上传文件不能为空文件");
|
||||
AppFileInfo fileInfo = fileService.uploadFile(file);
|
||||
return Result.success(fileInfo);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "文件删除")
|
||||
@SneakyThrows
|
||||
public Result<?> deleteFile(
|
||||
@Parameter(description = "文件路径") @RequestParam String filePath
|
||||
) {
|
||||
boolean result = fileService.deleteFile(filePath);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user