无关风月
5 天以前 b84fc1807a6ce71f4d10cdb10da186abc5dcc173
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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<String> upload(@RequestPart("file") MultipartFile file) {
        String fileUrl;
        try {
            fileUrl = ossService.uploadFile(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return R.ok(fileUrl);
    }
}