Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
import software.amazon.awssdk.services.s3.model.CopyObjectRequest;
import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

// snippet-end:[s3.java2.copy_object.import]
/**
* Copy an object from one Amazon S3 bucket to another.
Expand Down Expand Up @@ -59,9 +63,15 @@ public static void main(String[] args)
object_key, from_bucket, to_bucket);
Region region = Region.US_WEST_2;
S3Client s3 = S3Client.builder().region(region).build();
String encodedUrl = null;
try {
encodedUrl = URLEncoder.encode(from_bucket + "/" + object_key, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
System.out.println("URL could not be encoded: " + e.getMessage());
}

CopyObjectRequest copyReq = CopyObjectRequest.builder()
.copySource(from_bucket + "/" + object_key)
.copySource(encodedUrl)
.bucket(to_bucket)
.key(object_key)
.build();
Expand Down