|
|
|
@ -27,12 +27,26 @@ namespace S3Demo.Helper
|
|
|
|
|
/// object to be tagged.</param>
|
|
|
|
|
/// <param name="filePath">The directory location and file name of the
|
|
|
|
|
/// object to be uploaded to the S3 bucket.</param>
|
|
|
|
|
public static async Task<string> PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, string[] tags)
|
|
|
|
|
public static async Task<string> PutObjectsWithTagsAsync(IAmazonS3 client, string bucketName, string keyName, string filePath, List<string> tags)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Create an object with tags.
|
|
|
|
|
var putRequest = new PutObjectRequest
|
|
|
|
|
//List<string> keys = new List<string> { "sn", "date", "code" };
|
|
|
|
|
//var putRequest = new PutObjectRequest()
|
|
|
|
|
//{
|
|
|
|
|
// BucketName = bucketName,
|
|
|
|
|
// Key = keyName,
|
|
|
|
|
// FilePath = filePath
|
|
|
|
|
//};
|
|
|
|
|
//for (int i = 0; i < tags.Count; i++)
|
|
|
|
|
//{
|
|
|
|
|
// //TODO: 优化添加标签参数细节
|
|
|
|
|
// putRequest.TagSet = new List<Tag> {
|
|
|
|
|
// new Tag { Key = keys[i], Value = tags[i] }
|
|
|
|
|
// };
|
|
|
|
|
//}
|
|
|
|
|
var putRequest = new PutObjectRequest()
|
|
|
|
|
{
|
|
|
|
|
BucketName = bucketName,
|
|
|
|
|
Key = keyName,
|
|
|
|
@ -45,7 +59,6 @@ namespace S3Demo.Helper
|
|
|
|
|
//new Tag { Key = "code", Value = tags[2] }
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PutObjectResponse response = await client.PutObjectAsync(putRequest);
|
|
|
|
|
//Console.WriteLine(putRequest.Key + "," + putRequest.BucketName + "," + putRequest.FilePath + "," + response.HttpStatusCode);
|
|
|
|
|
return response.HttpStatusCode.ToString();
|
|
|
|
@ -97,7 +110,7 @@ namespace S3Demo.Helper
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Error: {ex.Message}");
|
|
|
|
|
//Console.WriteLine($"Error: {ex.Message}");
|
|
|
|
|
return ex.Message.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|