ایجاد برچسب برای یک آبجکت
مولفهها
- کلیدهای احراز هویت
- نام صندوقچه
- نام آبجکت
- برچسب
- NET.
- PHP
- Python
- Javascript
- GO
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace PutObjectTags
{
class PutObjectTags
{
private const string bucketName = "<BUCKET_NAME>";
private const string objectName = "<OBJECT_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);
PutObjectTagsAsync().Wait();
}
private static async Task PutObjectTagsAsync()
{
try
{
var tagging = new Tagging
{
TagSet = new List<Tag>
{
new Tag
{
Key = "key1",
Value = "value1"
}
}
};
// Set a new Tag set for object.
PutObjectTaggingResponse response = await _s3Client.PutObjectTaggingAsync(new PutObjectTaggingRequest
{
BucketName = bucketName,
Key = objectName,
Tagging = tagging
});
Console.WriteLine($"Tag set added to {objectName} object");
}
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>';
$params = [
'Bucket' => $bucket,
'ContentMD5' => '<string>',
'ExpectedBucketOwner' => '<string>',
'Key' => '<OBJECT_NAME>', // REQUIRED
'RequestPayer' => 'requester',
'Tagging' => [ // REQUIRED
'TagSet' => [ // REQUIRED
[
'Key' => '<string>', // REQUIRED
'Value' => '<string>', // REQUIRED
],
],
],
'VersionId' => '<string>',
];
try {
$resp = $client->putObjectTagging($params);
var_dump($resp);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}