package com.ruoyi.web.controller.system; import com.ruoyi.common.core.domain.R; import com.ruoyi.system.service.OssService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; 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.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; /** * @author mitao * @date 2025/9/19 */ @Api(tags = {"文件上传接口"}) @RestController @RequestMapping("/file-upload/") public class FileUploadController { @Autowired private OssService ossService; /** * 上传文件 * * @param file * @return */ @ApiOperation(value = "OSS文件上传") @PostMapping("/upload-oss") public R upload(@RequestPart("file") MultipartFile file) { String fileUrl; try { fileUrl = ossService.uploadFile(file); } catch (IOException e) { throw new RuntimeException(e); } return R.ok(fileUrl); } }