| package com.ruoyi.other.controller; | 
|   | 
|   | 
| import com.ruoyi.common.core.utils.ObsUploadUtil; | 
| import io.swagger.annotations.Api; | 
| 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 java.io.IOException; | 
|   | 
| @RestController | 
| @RequestMapping("/base/oss") | 
| @Api(value = "文件上传", tags = "文件上传", description = "文件上传") | 
| public class OssController { | 
|     private static final String endpoint = "obs.cn-north-4.myhuaweicloud.com"; | 
|     private static final String accessKeyId = "DRJFJRVQ9KVLQUSJUROI"; | 
|     private static final String accessKeySecret = "3zpPkULh0a8CTTYjKL4f7szQZECkvVol4SwNab0f"; | 
|     private static final String bucketName = "jkjianshen"; | 
|     @PostMapping("/upload") | 
|     @ApiOperation(value = "文件上传") | 
|     public String upload(@RequestParam("file") MultipartFile file) throws IOException { | 
|         String s = ObsUploadUtil.obsUpload(file); | 
|         return s; | 
|     } | 
| //    @PostMapping("/uploadVideo") | 
| //    @ApiOperation(value = "视频上传",tags = "文件上传") | 
| //    public String uploadVideo(@RequestParam("file") MultipartFile file) throws Exception { | 
| //        // 获取文件名 | 
| //        String fileName = file.getOriginalFilename(); | 
| //        // 构建目标文件路径 | 
| //        String filePath = "/usr/local/temp" + fileName; | 
| ////        String filePath = "C:/temp/" + fileName; | 
| //        // 创建目标文件对象 | 
| //        File targetFile = new File(filePath); | 
| //        // 将 MultipartFile 内容写入目标文件 | 
| //        try (FileOutputStream fos = new FileOutputStream(targetFile)) { | 
| //            fos.write(file.getBytes()); | 
| //        } | 
| //        String s = UploadVideoUtil.endUpload(targetFile.toString(), UUIDUtil.getRandomCode(5)+fileName); | 
| //        // 创建要删除的文件对象 | 
| //        File fileToDelete = new File(targetFile.toString()); | 
| //        // 检查文件是否存在,并删除文件 | 
| //        if (fileToDelete.exists()) { | 
| //            fileToDelete.delete(); | 
| //        } | 
| //        return s; | 
| //    } | 
|   | 
| //    @PostMapping("/upload") | 
| //    @ApiOperation(value = "文件上传",tags = "文件上传") | 
| //    public ResponseEntity<String> upload(@RequestParam("file") MultipartFile file) throws IOException { | 
| //        // 创建 OSSClient 实例 | 
| //        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); | 
| // | 
| // | 
| //        // 创建 PutObjectRequest 对象 | 
| //        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, file.getOriginalFilename(), file.getInputStream()); | 
| // | 
| //        ObjectMetadata metadata = new ObjectMetadata(); | 
| //        // 取消文件缓存,文件每次都会从OSS服务器获取 | 
| //        metadata.setHeader("Cache-Control", "no-cache"); | 
| //        metadata.setHeader("Expires", "0"); | 
| // | 
| // | 
| //        // 上传文件 | 
| //        PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest); | 
| // | 
| //        // 关闭 OSSClient 实例 | 
| //        ossClient.shutdown(); | 
| // | 
| //        String fileUrl = "https://" + bucketName + "." + endpoint + "/" + file.getOriginalFilename(); | 
| //        return ResponseEntity.ok(fileUrl); | 
| //    } | 
|   | 
|   | 
| } |