New file |
| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.web.controller.tool.TencentCosUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | 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 javax.annotation.Resource; |
| | | import java.io.OutputStream; |
| | | |
| | | /** |
| | | * @author HJL |
| | | * @version 1.0 |
| | | * @since 2024-05-30 9:27 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/cos") |
| | | @Api(tags = "公共-文件上传") |
| | | public class COSController { |
| | | |
| | | @Resource |
| | | private TencentCosUtil tencentCosUtil; |
| | | |
| | | @PostMapping("/upload") |
| | | @ApiOperation(value = "文件上传", tags = "公共-文件上传") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "文件", name = "file", dataType = "MultipartFile", required = true) |
| | | }) |
| | | public R<String> upload(@RequestParam("file") MultipartFile file) { |
| | | String url = tencentCosUtil.upLoadFile(file); |
| | | return R.ok(url, url); |
| | | } |
| | | @PostMapping("/download") |
| | | @ApiOperation(value = "文件下载", tags = "公共-文件下载") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "文件url", name = "url", dataType = "String", required = true) |
| | | }) |
| | | public void upload(@RequestParam("url") String url) { |
| | | tencentCosUtil.downLoadFile(url); |
| | | } |
| | | } |