File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
javav2/example_code/s3/src/main/java/com/example/s3 Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 27
27
import software .amazon .awssdk .services .s3 .model .CopyObjectRequest ;
28
28
import software .amazon .awssdk .services .s3 .model .CopyObjectResponse ;
29
29
import software .amazon .awssdk .services .s3 .model .S3Exception ;
30
-
30
+
31
+ import java .io .UnsupportedEncodingException ;
32
+ import java .net .URLEncoder ;
33
+ import java .nio .charset .StandardCharsets ;
34
+
31
35
// snippet-end:[s3.java2.copy_object.import]
32
36
/**
33
37
* Copy an object from one Amazon S3 bucket to another.
@@ -59,9 +63,15 @@ public static void main(String[] args)
59
63
object_key , from_bucket , to_bucket );
60
64
Region region = Region .US_WEST_2 ;
61
65
S3Client s3 = S3Client .builder ().region (region ).build ();
66
+ String encodedUrl = null ;
67
+ try {
68
+ encodedUrl = URLEncoder .encode (from_bucket + "/" + object_key , StandardCharsets .UTF_8 .toString ());
69
+ } catch (UnsupportedEncodingException e ) {
70
+ System .out .println ("URL could not be encoded: " + e .getMessage ());
71
+ }
62
72
63
73
CopyObjectRequest copyReq = CopyObjectRequest .builder ()
64
- .copySource (from_bucket + "/" + object_key )
74
+ .copySource (encodedUrl )
65
75
.bucket (to_bucket )
66
76
.key (object_key )
67
77
.build ();
You can’t perform that action at this time.
0 commit comments