Halaman ini belum tersedia dalam bahasa lokal Anda. Kami berusaha keras untuk menambahkan lebih banyak versi bahasa. Terima kasih atas dukungan Anda.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Listing Versioning Objects

Updated on 2023-11-09 GMT+08:00
NOTICE:

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see API Reference.

You can call ObsClient->listVersions to list versioning objects.

The following table describes the parameters involved in this API.

Parameter

Description

Prefix

Name prefix that the objects to be listed must contain

KeyMarker

Object name to start with when listing versioning objects in a bucket. All versioning objects whose names follow this parameter are listed in the lexicographical order.

MaxKeys

Maximum number of versioning objects returned. The value ranges from 1 to 1000. If the value is not in this range, 1000 versioning objects are returned by default.

Delimiter

Character used to group object names. If the object name contains the Delimiter parameter, the character string from the first character to the first delimiter in the object name is grouped under a single result element, CommonPrefix. (If a prefix is specified in the request, the prefix must be removed from the object name.)

VersionIdMarker

Object name to start with when listing versioning objects in a bucket. All versioning objects are listed in the lexicographical order by object name and version ID. This parameter must be used together with KeyMarker.

NOTE:
  • If the value of VersionIdMarker is not a version ID specified by KeyMarker, VersionIdMarker is ineffective.
  • The returned result of ObsClient->listVersions includes the versioning objects and delete markers.

Listing Versioning Objects in Simple Mode

The following sample code shows how to list versioning objects in simple mode. A maximum of 1000 versioning objects can be listed.

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$resp = $obsClient->listVersions ( [ 
       'Bucket' => 'bucketname' 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
// Obtain versioning objects.
printf ( "Versions:\n" );
foreach ( $resp ['Versions'] as $index => $version ) {
       printf ( "Versions[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $version ['Key'] );
       printf ( "VersionId:%s\n", $version ['VersionId'] );
       printf ( "IsLatest:%s\n", $version ['IsLatest'] );
       printf ( "LastModified:%s\n", $version ['LastModified'] );
       printf ( "ETag:%s\n", $version ['ETag'] );
       printf ( "Size:%s\n", $version ['Size'] );
       printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
       printf ( "StorageClass:%s\n", $version ['StorageClass'] );
}
// Obtain delete markers.
printf ( "DeleteMarkers:\n" );
foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
       printf ( "DeleteMarkers[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $deleteMarker ['Key'] );
       printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
       printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
       printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
}
NOTE:
  • Information about a maximum of 1000 versioning objects can be listed each time. If a bucket contains more than 1000 objects and IsTruncated is true in the returned result, not all versioning objects are listed. In such cases, you can use NextKeyMarker and NextVersionIdMarker to obtain the start position for next listing.
  • If you want to obtain all versioning objects in a specified bucket, you can use the paging mode for listing objects.

Listing Versioning Objects by Specifying the Number

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

// List 100 versioning objects.
$resp = $obsClient->listVersions ( [ 
       'Bucket' => 'bucketname',
       'MaxKeys' => 100
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
// Obtain versioning objects.
printf ( "Versions:\n" );
foreach ( $resp ['Versions'] as $index => $version ) {
       printf ( "Versions[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $version ['Key'] );
       printf ( "VersionId:%s\n", $version ['VersionId'] );
       printf ( "IsLatest:%s\n", $version ['IsLatest'] );
       printf ( "LastModified:%s\n", $version ['LastModified'] );
       printf ( "ETag:%s\n", $version ['ETag'] );
       printf ( "Size:%s\n", $version ['Size'] );
       printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
       printf ( "StorageClass:%s\n", $version ['StorageClass'] );
}
// Obtain delete markers.
printf ( "DeleteMarkers:\n" );
foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
       printf ( "DeleteMarkers[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $deleteMarker ['Key'] );
       printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
       printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
       printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
}

Listing Versioning Objects by Specifying a Prefix

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

// Set the prefix to prefix and the number to 100.
$resp = $obsClient->listVersions ( [ 
       'Bucket' => 'bucketname',
       'MaxKeys' => 100,
       'Prefix' => 'prefix'
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
// Obtain versioning objects.
printf ( "Versions:\n" );
foreach ( $resp ['Versions'] as $index => $version ) {
       printf ( "Versions[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $version ['Key'] );
       printf ( "VersionId:%s\n", $version ['VersionId'] );
       printf ( "IsLatest:%s\n", $version ['IsLatest'] );
       printf ( "LastModified:%s\n", $version ['LastModified'] );
       printf ( "ETag:%s\n", $version ['ETag'] );
       printf ( "Size:%s\n", $version ['Size'] );
       printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
        printf ( "StorageClass:%s\n", $version ['StorageClass'] );
}
// Obtain delete markers.
printf ( "DeleteMarkers:\n" );
foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
       printf ( "DeleteMarkers[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $deleteMarker ['Key'] );
       printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
       printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
       printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
}

Listing Versioning Objects by Specifying the Start Position

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

// List 100 versioning objects whose names are following test in lexicographical order.
$resp = $obsClient->listVersions ( [ 
       'Bucket' => 'bucketname',
       'MaxKeys' => 100,
       'Marker' => 'test'
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
// Obtain versioning objects.
printf ( "Versions:\n" );
foreach ( $resp ['Versions'] as $index => $version ) {
       printf ( "Versions[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $version ['Key'] );
       printf ( "VersionId:%s\n", $version ['VersionId'] );
       printf ( "IsLatest:%s\n", $version ['IsLatest'] );
       printf ( "LastModified:%s\n", $version ['LastModified'] );
       printf ( "ETag:%s\n", $version ['ETag'] );
       printf ( "Size:%s\n", $version ['Size'] );
       printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
       printf ( "StorageClass:%s\n", $version ['StorageClass'] );
}
// Obtain delete markers.
printf ( "DeleteMarkers:\n" );
foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
       printf ( "DeleteMarkers[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $deleteMarker ['Key'] );
       printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
       printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
       printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
}

Listing All Versioning Objects in Paging Mode

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$keyMarker = null;
$versionIdMarker = null;

do {
       $resp = $obsClient->listVersions ( [ 
              'Bucket' => 'bucketname',
              'MaxKeys' => 100,
              'Marker' => $keyMarker,
              'VersionIdMarker' => $versionIdMarker
       ] );
       printf ( "RequestId:%s\n", $resp ['RequestId'] );
       // Obtain versioning objects.
       printf ( "Versions:\n" );
       foreach ( $resp ['Versions'] as $index => $version ) {
              printf ( "Versions[%d]\n", $index + 1 );
              printf ( "Key:%s\n", $version ['Key'] );
              printf ( "VersionId:%s\n", $version ['VersionId'] );
              printf ( "IsLatest:%s\n", $version ['IsLatest'] );
              printf ( "LastModified:%s\n", $version ['LastModified'] );
              printf ( "ETag:%s\n", $version ['ETag'] );
              printf ( "Size:%s\n", $version ['Size'] );
              printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
              printf ( "StorageClass:%s\n", $version ['StorageClass'] );
       }
       // Obtain delete markers.
       printf ( "DeleteMarkers:\n" );
       foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
              printf ( "DeleteMarkers[%d]\n", $index + 1 );
              printf ( "Key:%s\n", $deleteMarker ['Key'] );
              printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
              printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
              printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
       }
       
       $keyMarker = $resp['NextKeyMarker'];
       $versionIdMarker = $resp['NextVersionIdMarker'];
}while($resp['IsTruncated']);

Listing All Versioning Objects in a Folder

There is no folder concept in OBS. All elements in buckets are objects. Folders are actually objects whose sizes are 0 and whose names end with a slash (/). When you set a folder name as the prefix, objects in this folder will be listed. Sample code is as follows:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$keyMarker = null;
$versionIdMarker = null;

do {
       $resp = $obsClient->listVersions ( [ 
              'Bucket' => 'bucketname',
              'MaxKeys' => 100,
              'Marker' => $keyMarker,
              'VersionIdMarker' => $versionIdMarker,
              // Set the prefix of the folders to dir/.
              'Prefix' => 'dir/'
       ] );
       printf ( "RequestId:%s\n", $resp ['RequestId'] );
       // Obtain versioning objects.
       printf ( "Versions:\n" );
       foreach ( $resp ['Versions'] as $index => $version ) {
              printf ( "Versions[%d]\n", $index + 1 );
              printf ( "Key:%s\n", $version ['Key'] );
              printf ( "VersionId:%s\n", $version ['VersionId'] );
              printf ( "IsLatest:%s\n", $version ['IsLatest'] );
              printf ( "LastModified:%s\n", $version ['LastModified'] );
              printf ( "ETag:%s\n", $version ['ETag'] );
              printf ( "Size:%s\n", $version ['Size'] );
              printf ( "Owner[ID]:%s\n", $version ['Owner'] ['ID'] );
              printf ( "StorageClass:%s\n", $version ['StorageClass'] );
       }
       // Obtain delete markers.
       printf ( "DeleteMarkers:\n" );
       foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
              printf ( "DeleteMarkers[%d]\n", $index + 1 );
              printf ( "Key:%s\n", $deleteMarker ['Key'] );
              printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
              printf ( "LastModified:%s\n", $deleteMarker ['LastModified'] );
              printf ( "Owner[ID]:%s\n", $deleteMarker ['Owner'] ['ID'] );
       }
       
       $keyMarker = $resp['NextKeyMarker'];
       $versionIdMarker = $resp['NextVersionIdMarker'];
}while($resp['IsTruncated']);

Listing All Versioning Objects According to Folders in a Bucket

Sample code:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
      //Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
      //Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

function listVersionsByPrefix($commonPrefixes){
       global $obsClient;
       foreach ($commonPrefixes as $commonPrefix){
              $resp = $obsClient->listVersions ( [
                           'Bucket' => 'bucketname',
                           // Set folder isolators to slashes (/).
                           'Delimiter' => '/',
                           'Prefix' => $commonPrefix['Prefix']
              ] );
              printf ( "Objects in folder [%s]:\n ", $commonPrefix['Prefix']);
              // Obtain versioning objects.
              printf ( "Versions:\n" );
              foreach ( $resp ['Versions'] as $index => $version ) {
                     printf ( "Versions[%d]\n", $index + 1 );
                     printf ( "Key:%s\n", $version ['Key'] );
                     printf ( "VersionId:%s\n", $version ['VersionId'] );
              }
              // Obtain delete markers.
              printf ( "DeleteMarkers:\n" );
              foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
                     printf ( "DeleteMarkers[%d]\n", $index + 1 );
                     printf ( "Key:%s\n", $deleteMarker ['Key'] );
                     printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
              }
              printf("\n");
              listVersionsByPrefix($resp['CommonPrefixes']);
       }
}

$resp = $obsClient->listVersions ( [ 
       'Bucket' => 'bucketname',
       // Set folder isolators to slashes (/).
       'Delimiter' => '/'
] );
printf ( "Objects in the root directory:\n ");
// Obtain versioning objects.
printf ( "Versions:\n" );
foreach ( $resp ['Versions'] as $index => $version ) {
       printf ( "Versions[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $version ['Key'] );
       printf ( "VersionId:%s\n", $version ['VersionId'] );
}
              // Obtain delete markers.
printf ( "DeleteMarkers:\n" );
foreach ( $resp ['DeleteMarkers'] as $index => $deleteMarker ) {
       printf ( "DeleteMarkers[%d]\n", $index + 1 );
       printf ( "Key:%s\n", $deleteMarker ['Key'] );
       printf ( "VersionId:%s\n", $deleteMarker ['VersionId'] );
}
printf("\n");

listVersionsByPrefix($resp['CommonPrefixes']);
NOTE:
  • The previous sample code does not include scenarios where the number of objects in a folder exceeds 1000.
  • Because objects and sub-folders in a folder are to be listed and all the objects end with a slash (/), Delimiter is always a slash (/).
  • In the returned result of each recursion, Versions includes the versioning objects in the folder, DeleteMarkers includes the delete markers in the folder, and CommonPrefixes includes the sub-folders in the folder.

Kami menggunakan cookie untuk meningkatkan kualitas situs kami dan pengalaman Anda. Dengan melanjutkan penelusuran di situs kami berarti Anda menerima kebijakan cookie kami. Cari tahu selengkapnya

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback