123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /**
- * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.springblade.modules.resource;
- import io.swagger.annotations.Api;
- import lombok.AllArgsConstructor;
- import lombok.SneakyThrows;
- import org.springblade.core.oss.QiniuTemplate;
- import org.springblade.core.oss.model.BladeFile;
- import org.springblade.core.oss.model.OssFile;
- import org.springblade.core.tool.api.R;
- import org.springblade.core.tool.utils.Func;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- /**
- * 对象存储端点
- *
- * @author Chill
- */
- @RestController
- @AllArgsConstructor
- @RequestMapping("/blade-resource/oss/endpoint")
- @Api(value = "对象存储端点", tags = "对象存储端点")
- public class OssEndpoint {
- private QiniuTemplate qiniuTemplate;
- /**
- * 创建存储桶
- *
- * @param bucketName 存储桶名称
- * @return Bucket
- */
- @SneakyThrows
- @PostMapping("/make-bucket")
- public R makeBucket(@RequestParam String bucketName) {
- qiniuTemplate.makeBucket(bucketName);
- return R.success("创建成功");
- }
- /**
- * 创建存储桶
- *
- * @param bucketName 存储桶名称
- * @return R
- */
- @SneakyThrows
- @PostMapping("/remove-bucket")
- public R removeBucket(@RequestParam String bucketName) {
- qiniuTemplate.removeBucket(bucketName);
- return R.success("删除成功");
- }
- /**
- * 拷贝文件
- *
- * @param fileName 存储桶对象名称
- * @param destBucketName 目标存储桶名称
- * @param destFileName 目标存储桶对象名称
- * @return R
- */
- @SneakyThrows
- @PostMapping("/copy-file")
- public R copyFile(@RequestParam String fileName, @RequestParam String destBucketName, String destFileName) {
- qiniuTemplate.copyFile(fileName, destBucketName, destFileName);
- return R.success("操作成功");
- }
- /**
- * 获取文件信息
- *
- * @param fileName 存储桶对象名称
- * @return InputStream
- */
- @SneakyThrows
- @GetMapping("/stat-file")
- public R<OssFile> statFile(@RequestParam String fileName) {
- return R.data(qiniuTemplate.statFile(fileName));
- }
- /**
- * 获取文件相对路径
- *
- * @param fileName 存储桶对象名称
- * @return String
- */
- @SneakyThrows
- @GetMapping("/file-path")
- public R<String> filePath(@RequestParam String fileName) {
- return R.data(qiniuTemplate.filePath(fileName));
- }
- /**
- * 获取文件外链
- *
- * @param fileName 存储桶对象名称
- * @return String
- */
- @SneakyThrows
- @GetMapping("/file-link")
- public R<String> fileLink(@RequestParam String fileName) {
- return R.data(qiniuTemplate.fileLink(fileName));
- }
- /**
- * 上传文件
- *
- * @param file 文件
- * @return ObjectStat
- */
- @SneakyThrows
- @PostMapping("/put-file")
- public R<BladeFile> putFile(@RequestParam MultipartFile file) {
- BladeFile bladeFile = qiniuTemplate.putFile(file.getOriginalFilename(), file.getInputStream());
- return R.data(bladeFile);
- }
- /**
- * 上传文件
- *
- * @param fileName 存储桶对象名称
- * @param file 文件
- * @return ObjectStat
- */
- @SneakyThrows
- @PostMapping("/put-file-by-name")
- public R<BladeFile> putFile(@RequestParam String fileName, @RequestParam MultipartFile file) {
- BladeFile bladeFile = qiniuTemplate.putFile(fileName, file.getInputStream());
- return R.data(bladeFile);
- }
- /**
- * 删除文件
- *
- * @param fileName 存储桶对象名称
- * @return R
- */
- @SneakyThrows
- @PostMapping("/remove-file")
- public R removeFile(@RequestParam String fileName) {
- qiniuTemplate.removeFile(fileName);
- return R.success("操作成功");
- }
- /**
- * 批量删除文件
- *
- * @param fileNames 存储桶对象名称集合
- * @return R
- */
- @SneakyThrows
- @PostMapping("/remove-files")
- public R removeFiles(@RequestParam String fileNames) {
- qiniuTemplate.removeFiles(Func.toStrList(fileNames));
- return R.success("操作成功");
- }
- }
|