51 lines
1.6 KiB
Java
51 lines
1.6 KiB
Java
package com.ycwl.basic.controller;
|
|
|
|
|
|
import com.ycwl.basic.annotation.IgnoreToken;
|
|
import com.ycwl.basic.enums.BizCodeEnum;
|
|
import com.ycwl.basic.service.FileService;
|
|
import com.ycwl.basic.utils.ApiResponse;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* @Author: songmingsong
|
|
* @CreateTime: 2024-12-05
|
|
* @Description: 文件接口
|
|
* @Version: 1.0
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/file/v1")
|
|
@Slf4j
|
|
@Api(tags = "文件接口")
|
|
public class FileController {
|
|
|
|
@Autowired
|
|
private FileService fileService;
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
@PostMapping("/upload")
|
|
@IgnoreToken
|
|
public ApiResponse<?> upload(@RequestParam(value = "file") MultipartFile file) throws IOException {
|
|
String url = fileService.uploadFile(file);
|
|
return ApiResponse.success(url);
|
|
}
|
|
|
|
@ApiOperation(value = "删除文件")
|
|
@PostMapping("/delete")
|
|
@IgnoreToken
|
|
public ApiResponse<?> delete(@RequestParam(value = "fileName") String fileName) throws IOException {
|
|
Boolean flag = fileService.delete(fileName);
|
|
return flag ? ApiResponse.success(BizCodeEnum.REQUEST_OK) : ApiResponse.fail(BizCodeEnum.FAIL.getMessage());
|
|
}
|
|
}
|