- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
ListObjectVersionsCommand
This operation is not supported for directory buckets.
Returns metadata about all versions of the objects in a bucket. You can also use request parameters as selection criteria to return metadata about a subset of all the object versions.
To use this operation, you must have permission to perform the s3:ListBucketVersions
action. Be aware of the name difference.
A 200 OK
response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately.
To use this operation, you must have READ access to the bucket.
The following operations are related to ListObjectVersions
:
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { S3Client, ListObjectVersionsCommand } from "@aws-sdk/client-s3"; // ES Modules import
// const { S3Client, ListObjectVersionsCommand } = require("@aws-sdk/client-s3"); // CommonJS import
const client = new S3Client(config);
const input = { // ListObjectVersionsRequest
Bucket: "STRING_VALUE", // required
Delimiter: "STRING_VALUE",
EncodingType: "url",
KeyMarker: "STRING_VALUE",
MaxKeys: Number("int"),
Prefix: "STRING_VALUE",
VersionIdMarker: "STRING_VALUE",
ExpectedBucketOwner: "STRING_VALUE",
RequestPayer: "requester",
OptionalObjectAttributes: [ // OptionalObjectAttributesList
"RestoreStatus",
],
};
const command = new ListObjectVersionsCommand(input);
const response = await client.send(command);
// { // ListObjectVersionsOutput
// IsTruncated: true || false,
// KeyMarker: "STRING_VALUE",
// VersionIdMarker: "STRING_VALUE",
// NextKeyMarker: "STRING_VALUE",
// NextVersionIdMarker: "STRING_VALUE",
// Versions: [ // ObjectVersionList
// { // ObjectVersion
// ETag: "STRING_VALUE",
// ChecksumAlgorithm: [ // ChecksumAlgorithmList
// "CRC32" || "CRC32C" || "SHA1" || "SHA256",
// ],
// Size: Number("long"),
// StorageClass: "STANDARD",
// Key: "STRING_VALUE",
// VersionId: "STRING_VALUE",
// IsLatest: true || false,
// LastModified: new Date("TIMESTAMP"),
// Owner: { // Owner
// DisplayName: "STRING_VALUE",
// ID: "STRING_VALUE",
// },
// RestoreStatus: { // RestoreStatus
// IsRestoreInProgress: true || false,
// RestoreExpiryDate: new Date("TIMESTAMP"),
// },
// },
// ],
// DeleteMarkers: [ // DeleteMarkers
// { // DeleteMarkerEntry
// Owner: {
// DisplayName: "STRING_VALUE",
// ID: "STRING_VALUE",
// },
// Key: "STRING_VALUE",
// VersionId: "STRING_VALUE",
// IsLatest: true || false,
// LastModified: new Date("TIMESTAMP"),
// },
// ],
// Name: "STRING_VALUE",
// Prefix: "STRING_VALUE",
// Delimiter: "STRING_VALUE",
// MaxKeys: Number("int"),
// CommonPrefixes: [ // CommonPrefixList
// { // CommonPrefix
// Prefix: "STRING_VALUE",
// },
// ],
// EncodingType: "url",
// RequestCharged: "requester",
// };
Example Usage
ListObjectVersionsCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
Bucket Required | string | undefined | The bucket name that contains the objects. Note: To supply the Multi-region Access Point (MRAP) to Bucket, you need to install the "aws-sdk/signature-v4-crt" package to your project dependencies. For more information, please go to https://github.com/aws/aws-sdk-js-v3#known-issues |
Delimiter | string | undefined | A delimiter is a character that you specify to group keys. All keys that contain the same string between the |
EncodingType | EncodingType | undefined | Encoding type used by Amazon S3 to encode the object keys in the response. Responses are encoded only in UTF-8. An object key can contain any Unicode character. However, the XML 1.0 parser can't parse certain characters, such as characters with an ASCII value from 0 to 10. For characters that aren't supported in XML 1.0, you can add this parameter to request that Amazon S3 encode the keys in the response. For more information about characters to avoid in object key names, see Object key naming guidelines . When using the URL encoding type, non-ASCII characters that are used in an object's key name will be percent-encoded according to UTF-8 code values. For example, the object |
ExpectedBucketOwner | string | undefined | The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code |
KeyMarker | string | undefined | Specifies the key to start with when listing objects in a bucket. |
MaxKeys | number | undefined | Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more. If additional keys satisfy the search criteria, but were not returned because |
OptionalObjectAttributes | OptionalObjectAttributes[] | undefined | Specifies the optional fields that you want returned in the response. Fields that you do not specify are not returned. |
Prefix | string | undefined | Use this parameter to select only those keys that begin with the specified prefix. You can use prefixes to separate a bucket into different groupings of keys. (You can think of using |
RequestPayer | RequestPayer | undefined | Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. If either the source or destination S3 bucket has Requester Pays enabled, the requester will pay for corresponding charges to copy the object. For information about downloading objects from Requester Pays buckets, see Downloading Objects in Requester Pays Buckets in the Amazon S3 User Guide. This functionality is not supported for directory buckets. |
VersionIdMarker | string | undefined | Specifies the object version you want to start listing from. |
ListObjectVersionsCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
CommonPrefixes | CommonPrefix[] | undefined | All of the keys rolled up into a common prefix count as a single return when calculating the number of returns. |
DeleteMarkers | DeleteMarkerEntry[] | undefined | Container for an object that is a delete marker. |
Delimiter | string | undefined | The delimiter grouping the included keys. A delimiter is a character that you specify to group keys. All keys that contain the same string between the prefix and the first occurrence of the delimiter are grouped under a single result element in |
EncodingType | EncodingType | undefined | Encoding type used by Amazon S3 to encode object key names in the XML response. If you specify the |
IsTruncated | boolean | undefined | A flag that indicates whether Amazon S3 returned all of the results that satisfied the search criteria. If your results were truncated, you can make a follow-up paginated request by using the |
KeyMarker | string | undefined | Marks the last key returned in a truncated response. |
MaxKeys | number | undefined | Specifies the maximum number of objects to return. |
Name | string | undefined | The bucket name. |
NextKeyMarker | string | undefined | When the number of responses exceeds the value of |
NextVersionIdMarker | string | undefined | When the number of responses exceeds the value of |
Prefix | string | undefined | Selects objects that start with the value supplied by this parameter. |
RequestCharged | RequestCharged | undefined | If present, indicates that the requester was successfully charged for the request. This functionality is not supported for directory buckets. |
VersionIdMarker | string | undefined | Marks the last version of the key returned in a truncated response. |
Versions | ObjectVersion[] | undefined | Container for version information. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
S3ServiceException | Base exception class for all service exceptions from S3 service. |