From 8e8e882d322196d6578ece16595bbfded302acf9 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Sun, 21 Jan 2024 15:00:04 +0800 Subject: [PATCH] S3 copy object sample code --- .../com/luoo/user/controller/S3Controller.java | 18 ++++++++++++++++++ .../java/com/luoo/user/service/S3Service.java | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/S3Controller.java b/luoo_user/src/main/java/com/luoo/user/controller/S3Controller.java index 1fa5a1b..875be8c 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/S3Controller.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/S3Controller.java @@ -33,6 +33,18 @@ public class S3Controller { return Result.success(); } + + /** + * 文件存储目录规划 + * + * music 存放期刊和期刊歌曲 二级目录为期刊期刊号 三级目录存放期刊歌曲和封面图片和歌曲图片 + * + * song 存放通用歌曲 + * + * image存放图片 + * + * + */ @PostMapping("/awsUpload") public Result upload(MultipartFile file) { @@ -50,4 +62,10 @@ public class S3Controller { return Result.success(); } + + @PostMapping("/awsCopy") + public Result copy() { + s3Service.copy(); + return Result.success(); + } } diff --git a/luoo_user/src/main/java/com/luoo/user/service/S3Service.java b/luoo_user/src/main/java/com/luoo/user/service/S3Service.java index 6dc0651..3f26e6b 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/S3Service.java +++ b/luoo_user/src/main/java/com/luoo/user/service/S3Service.java @@ -79,4 +79,20 @@ public class S3Service { return 1; } + + + + public int copy() { + + String bucket = "indie"; //存储桶名 + String sourceKey = "20240121/1.mp3"; //copy的源文件路径 + String destinationKey = "20240121/2.mp3"; // copy的目的地路径 + CopyObjectResponse copyObjectResponse = s3Client.copyObject(CopyObjectRequest.builder().sourceBucket(bucket).sourceKey(sourceKey).destinationBucket(bucket).destinationKey(destinationKey).build()); + SdkHttpResponse sdkHttpResponse = copyObjectResponse.sdkHttpResponse(); + if(!sdkHttpResponse.isSuccessful()){ + return -1; + } + return 1; + } + }