دریافت وضعیت فعال بودن نگهداری نسخههای مختلف آبجکت
برای دریافت وضعیت فعال بودن یا نبودن نگهداری نسخههای مختلف آبجکت (Versioning) بهشکل زیر عمل میکنیم.
مولفهها
- کلیدهای احراز هویت
- نام صندوقچه
- NET.
- PHP
- Python
- Javascript
- GO
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Reflection;
using Newtonsoft.Json;
namespace GetBucketVersioningExample
{
class GetBucketVersioning
{
private const string bucketName = "<BUCKET_NAME>";
private static IAmazonS3 _s3Client;
public static void Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS-KEY>", "<SECRET-KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
GetBucketVersioningAsync().Wait();
}
private static async Task GetBucketVersioningAsync()
{
try
{
GetBucketVersioningResponse response = await _s3Client.GetBucketVersioningAsync(new GetBucketVersioningRequest
{
BucketName = bucketName,
});
Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}
<?php
require('client.php');
$bucket = '<BUCKET_NAME>';
try {
$result = $client->getBucketVersioning([
'Bucket' => $bucket, // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
import boto3
import logging
from botocore.exceptions import ClientError
logging.basicConfig(level=logging.INFO)
try:
s3_client = boto3.client(
's3',
endpoint_url='<ENDPOINT>',
aws_access_key_id='<ACCESS-KEY>',
aws_secret_access_key='<SECRET-KEY>'
)
except Exception as exc:
logging.error(exc)
else:
try:
bucket_name = '<BUCKET_NAME>'
response = s3_client.get_bucket_versioning(Bucket=bucket_name)
logging.info(response)
except ClientError as exc:
logging.error(exc)