| | |
| | | package com.ruoyi.file.controller; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.file.FileUtils; |
| | | import com.ruoyi.file.service.ISysFileService; |
| | | import com.ruoyi.file.utils.StateCloudObsUtil; |
| | | import com.ruoyi.system.api.domain.SysFile; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RequestPart; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.file.FileUtils; |
| | | import com.ruoyi.file.service.ISysFileService; |
| | | import com.ruoyi.system.api.domain.SysFile; |
| | | |
| | | /** |
| | | * 文件请求处理 |
| | |
| | | /** |
| | | * 文件上传请求 |
| | | */ |
| | | @PostMapping("upload") |
| | | @PostMapping("/upload") |
| | | public R<SysFile> upload(MultipartFile file) |
| | | { |
| | | try |
| | |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件上传请求 |
| | | */ |
| | | @ApiOperation(value = "obs文件上传", notes = "obs文件上传") |
| | | @PostMapping("/obs/upload") |
| | | public R<String> obsUpload(@RequestPart("file") MultipartFile file) { |
| | | try { |
| | | // 上传并返回访问地址 |
| | | String url = StateCloudObsUtil.uploadFile(file); |
| | | return R.ok(url); |
| | | } catch (Exception e) { |
| | | log.error("上传文件失败", e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件上传请求 |
| | | */ |
| | | @ApiOperation(value = "obs文件批量上传", notes = "obs文件批量上传") |
| | | @PostMapping("/obs/upload-batch") |
| | | public R<List<String>> obsUploadBatch(@RequestPart("file") MultipartFile[] file) { |
| | | List<String> urls = new ArrayList<>(); |
| | | try { |
| | | for (MultipartFile multipartFile : file) { |
| | | String url = StateCloudObsUtil.uploadFile(multipartFile); |
| | | urls.add(url); |
| | | } |
| | | // 上传并返回访问地址 |
| | | return R.ok(urls); |
| | | } catch (Exception e) { |
| | | log.error("上传文件失败", e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/obs/upload/stream") |
| | | public R<String> obsUpload(@RequestParam("code") String code, |
| | | @RequestParam("stream") InputStream stream) { |
| | | try { |
| | | // 上传并返回访问地址 |
| | | String url = StateCloudObsUtil.obsUploadStream(code, stream); |
| | | return R.ok(url); |
| | | } catch (Exception e) { |
| | | log.error("上传文件失败", e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | } |