S3 copy object sample code

main
wangqing 10 months ago
parent baaa64c3ad
commit 8e8e882d32

@ -33,6 +33,18 @@ public class S3Controller {
return Result.success(); return Result.success();
} }
/**
*
*
* music
*
* song
*
* image
*
*
*/
@PostMapping("/awsUpload") @PostMapping("/awsUpload")
public Result upload(MultipartFile file) { public Result upload(MultipartFile file) {
@ -50,4 +62,10 @@ public class S3Controller {
return Result.success(); return Result.success();
} }
@PostMapping("/awsCopy")
public Result copy() {
s3Service.copy();
return Result.success();
}
} }

@ -79,4 +79,20 @@ public class S3Service {
return 1; 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;
}
} }

Loading…
Cancel
Save