public void UpdateObjectTagging() { GetObjectTagging(); Tagging tags = new Tagging(); tags.TagSet = new List <Tag> { new Tag { Key = "Key1", Value = "Val1" }, new Tag { Key = "Key2", Value = "Val2" } }; PutObjectTaggingRequest request = new PutObjectTaggingRequest { BucketName = strBucketName, Key = strObjectName, Tagging = tags }; PutObjectTaggingResponse response = client.PutObjectTagging(request); if (response.HttpStatusCode.IsSuccess()) { Console.WriteLine("Object Tags updated successfully"); } GetObjectTagging(); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { PutObjectTaggingResponse putObjectTaggingResponse = new PutObjectTaggingResponse(); UnmarshallResult(context, putObjectTaggingResponse); return(putObjectTaggingResponse); }
public void UpdateObjectTagging() { Tagging tags = new Tagging(); tags.TagSet = new List <Tag> { new Tag { Key = "TagKey1", Value = "TagValue1" }, new Tag { Key = "TagKey2", Value = "TagValue2" }, }; PutObjectTaggingRequest request = new PutObjectTaggingRequest { BucketName = bucketName, Key = "test.txt", Tagging = tags }; PutObjectTaggingResponse response = client.PutObjectTagging(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine("basarlı, değiştirme."); } Console.ReadLine(); GetObjectTagging(); }
private static void UnmarshallResult(XmlUnmarshallerContext context, PutObjectTaggingResponse response) { IWebResponseData responseData = context.ResponseData; if (responseData.IsHeaderPresent("x-amz-version-id")) response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id")); return; }
private async Task <bool> sets3tag(string id, string newkey, string newvalue) { IAmazonS3 s3Client; Tagging newTagSet = new Tagging(); newTagSet.TagSet = new List <Tag> { new Tag { Key = newkey, Value = newvalue } }; if (awsAccessKey == null) { initcreds(); } using (s3Client = new AmazonS3Client(awsAccessKey, awsSecretAccessKey, awsregionep)) { PutObjectTaggingRequest putObjTagsRequest = new PutObjectTaggingRequest(); putObjTagsRequest.BucketName = bucketName; putObjTagsRequest.Key = id; putObjTagsRequest.Tagging = newTagSet; PutObjectTaggingResponse response = await s3Client.PutObjectTaggingAsync(putObjTagsRequest); if (response.HttpStatusCode == HttpStatusCode.OK) { return(true); } } return(false); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { PutObjectTaggingResponse response = new PutObjectTaggingResponse(); UnmarshallResult(context, response); return response; }
private static void UnmarshallResult(XmlUnmarshallerContext context, PutObjectTaggingResponse response) { IWebResponseData responseData = context.get_ResponseData(); if (responseData.IsHeaderPresent("x-amz-version-id")) { response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id")); } }
static void WriteObjectTags() { string id = Common.InputString("Key:", null, false); int ver = Common.InputInteger("Version:", 1, true, false); string key = Common.InputString("Tag Key:", null, false); string val = Common.InputString("Tag Value:", null, false); PutObjectTaggingRequest request = new PutObjectTaggingRequest(); request.BucketName = _Bucket; request.Key = id; request.VersionId = ver.ToString(); Tag tag = new Tag(); tag.Key = key; tag.Value = val; request.Tagging = new Tagging(); request.Tagging.TagSet = new List <Tag>(); request.Tagging.TagSet.Add(tag); PutObjectTaggingResponse response = _S3Client.PutObjectTaggingAsync(request).Result; int statusCode = (int)response.HttpStatusCode; if (response != null) { Console.WriteLine("Success"); return; } else { Console.WriteLine("Failed"); return; } }
/// <summary> /// This method uploads an object with tags. It then shows the tag /// values, changes the tags, and shows the new tags. /// </summary> /// <param name="client">The Initialized Amazon S3 client object used /// to call the methods to create and change an objects tags.</param> /// <param name="bucketName">A string representing the name of the /// bucket where the object will be stored.</param> /// <param name="keyName">A string representing the key name of the /// object to be tagged.</param> /// <param name="filePath">The directory location and file name of the /// object to be uploaded to the Amazon S3 bucket.</param> public static async Task PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath) { try { // Create an object with tags. var putRequest = new PutObjectRequest { BucketName = bucketName, Key = keyName, FilePath = filePath, TagSet = new List <Tag> { new Tag { Key = "Keyx1", Value = "Value1" }, new Tag { Key = "Keyx2", Value = "Value2" }, }, }; PutObjectResponse response = await client.PutObjectAsync(putRequest); // Now retrieve the new object's tags. GetObjectTaggingRequest getTagsRequest = new() { BucketName = bucketName, Key = keyName, }; GetObjectTaggingResponse objectTags = await client.GetObjectTaggingAsync(getTagsRequest); // Display the tag values. objectTags.Tagging .ForEach(t => Console.WriteLine($"Key: {t.Key}, Value: {t.Value}")); Tagging newTagSet = new() { TagSet = new List <Tag> { new Tag { Key = "Key3", Value = "Value3" }, new Tag { Key = "Key4", Value = "Value4" }, }, }; PutObjectTaggingRequest putObjTagsRequest = new () { BucketName = bucketName, Key = keyName, Tagging = newTagSet, }; PutObjectTaggingResponse response2 = await client.PutObjectTaggingAsync(putObjTagsRequest); // Retrieve the tags again and show the values. GetObjectTaggingRequest getTagsRequest2 = new() { BucketName = bucketName, Key = keyName, }; GetObjectTaggingResponse objectTags2 = await client.GetObjectTaggingAsync(getTagsRequest2); objectTags2.Tagging .ForEach(t => Console.WriteLine($"Key: {t.Key}, Value: {t.Value}")); } catch (AmazonS3Exception ex) { Console.WriteLine( $"Error: '{ex.Message}'"); } }
static async Task PutObjectWithTagsTestAsync() { try { // 1. Put an object with tags. var putRequest = new PutObjectRequest { BucketName = bucketName, Key = keyName, FilePath = filePath, TagSet = new List <Tag> { new Tag { Key = "Keyx1", Value = "Value1" }, new Tag { Key = "Keyx2", Value = "Value2" } } }; PutObjectResponse response = await client.PutObjectAsync(putRequest); // 2. Retrieve the object's tags. GetObjectTaggingRequest getTagsRequest = new GetObjectTaggingRequest { BucketName = bucketName, Key = keyName }; GetObjectTaggingResponse objectTags = await client.GetObjectTaggingAsync(getTagsRequest); for (int i = 0; i < objectTags.Tagging.Count; i++) { Console.WriteLine("Key: {0}, Value: {1}", objectTags.Tagging[i].Key, objectTags.Tagging[i].Value); } // 3. Replace the tagset. Tagging newTagSet = new Tagging(); newTagSet.TagSet = new List <Tag> { new Tag { Key = "Key3", Value = "Value3" }, new Tag { Key = "Key4", Value = "Value4" } }; PutObjectTaggingRequest putObjTagsRequest = new PutObjectTaggingRequest() { BucketName = bucketName, Key = keyName, Tagging = newTagSet }; PutObjectTaggingResponse response2 = await client.PutObjectTaggingAsync(putObjTagsRequest); // 4. Retrieve the object's tags. GetObjectTaggingRequest getTagsRequest2 = new GetObjectTaggingRequest(); getTagsRequest2.BucketName = bucketName; getTagsRequest2.Key = keyName; GetObjectTaggingResponse objectTags2 = await client.GetObjectTaggingAsync(getTagsRequest2); for (int i = 0; i < objectTags2.Tagging.Count; i++) { Console.WriteLine("Key: {0}, Value: {1}", objectTags2.Tagging[i].Key, objectTags2.Tagging[i].Value); } } catch (AmazonS3Exception e) { Console.WriteLine( "Error encountered ***. Message:'{0}' when writing an object" , e.Message); } catch (Exception e) { Console.WriteLine( "Encountered an error. Message:'{0}' when writing an object" , e.Message); } }