1- ############
2- | S3 | Objects
3- ############
1+ #####################
2+ Operations on Objects
3+ #####################
44
55An |S3 | object represents a *file *, or collection of data. Every object must reside within a
66:doc: `bucket <buckets >`.
@@ -9,6 +9,8 @@ An |S3| object represents a *file*, or collection of data. Every object must res
99
1010.. contents ::
1111 :local:
12+ :depth: 1
13+
1214
1315.. _upload-object :
1416
@@ -18,6 +20,13 @@ Upload an object
1820Use the |s3client | client's :methodname: `putObject ` method, supplying it with a bucket name, key
1921name, and file to upload. *The bucket must exist, or an error will result *.
2022
23+ **Imports: **
24+
25+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/PutObject.java
26+ :lines: 15-17
27+
28+ **Code: **
29+
2130.. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/PutObject.java
2231 :lines: 47-54
2332 :dedent: 8
@@ -30,19 +39,22 @@ List objects
3039To get a list of objects within a bucket, use the |s3client | client's :methodname: `listObjects `
3140method, supplying it with the name of a bucket.
3241
33- .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/ListObjects.java
34- :lines: 46-47
35- :dedent: 8
36-
3742The :methodname: `listObjects ` method returns an :java-api: `ObjectListing
3843<services/s3/model/ObjectListing> ` object that provides information about the objects in the bucket.
3944To list the object names (keys), use the :methodname: `getObjectSummaries ` method to get a List of
4045:java-api: `S3ObjectSummary <services/s3/model/S3ObjectSummary> ` objects, each of which represents a
4146single object in the bucket, then call its :methodname: `getKey ` method to retrieve the object's
4247name.
4348
49+ **Imports: **
50+
51+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/ListObjects.java
52+ :lines: 16-20
53+
54+ **Code: **
55+
4456.. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/ListObjects.java
45- :lines: 48 -52
57+ :lines: 46 -52
4658 :dedent: 8
4759
4860
@@ -64,11 +76,43 @@ object.
6476The following example downloads an object from S3 and saves its contents to a file (using the same
6577name as the object's key):
6678
79+ **Imports: **
80+
81+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/GetObject.java
82+ :lines: 15-23
83+
84+ **Code: **
85+
6786.. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/GetObject.java
6887 :lines: 51-75
6988 :dedent: 8
7089
7190
91+ .. _copy-object :
92+
93+ Copying, moving or renaming objects
94+ ===================================
95+
96+ You can copy an object from one bucket to another by using the |s3client | client's
97+ :methodname: `copyObject ` method. It takes the name of the bucket to copy from, the object to copy,
98+ and the destination bucket and name.
99+
100+ **Imports: **
101+
102+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/CopyObject.java
103+ :lines: 15-17
104+
105+ **Code: **
106+
107+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/CopyObject.java
108+ :lines: 45-54
109+ :dedent: 8
110+
111+ You can use :methodname: `copyObject ` with :ref: `deleteObject <delete-object >` to **move ** or
112+ **rename ** an object, by first copying the object to a new name (you can use the same bucket as both
113+ the source and destination) and then deleting the object from its old location.
114+
115+
72116.. _delete-object :
73117
74118Delete an object
@@ -77,7 +121,35 @@ Delete an object
77121Use the |s3client | client's :methodname: `deleteObject ` method, passing it the name of a bucket and
78122object to delete. *The specified bucket and object key must exist, or an error will result *.
79123
124+ **Imports: **
125+
126+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/DeleteObject.java
127+ :lines: 15-17
128+
129+ **Code: **
130+
80131.. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/DeleteObject.java
81132 :lines: 48-55
82133 :dedent: 8
83134
135+
136+ .. _delete-objects :
137+
138+ Deleting multiple objects at once
139+ =================================
140+
141+ Using the |s3client | client's :methodname: `deleteObjects ` method, you can delete multiple objects
142+ from the same bucket by passing their names to the :java-api: `DeleteObjectRequest
143+ <services/s3/model/DeleteObjectsRequest> ` :methodname: `withKeys ` method.
144+
145+ **Imports: **
146+
147+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/DeleteObjects.java
148+ :lines: 15-18
149+
150+ **Code: **
151+
152+ .. literalinclude :: ../../example_code/s3/src/main/java/aws/example/s3/DeleteObjects.java
153+ :lines: 53-62
154+ :dedent: 8
155+
0 commit comments