最近更新时间:2021-10-29
以下代码用于获取桶的文件列表。
using System; using Amazon.S3; using Amazon.S3.Model;
namespace ListObjectsV2 { class Program { static void Main() { var Ak = ""; var Sk = ""; var endpoint = "http://s3-test.com"; AmazonS3Client serviceClient = new AmazonS3Client(Ak,Sk, new AmazonS3Config{ ServiceURL = endpoint });
try { ListObjectsV2Response response; ListObjectsV2Request listObjects = new ListObjectsV2Request{ BucketName = "xxx", };
response = serviceClient.ListObjectsV2Async(listObjects).GetAwaiter().GetResult(); Console.WriteLine("Object Count is {0}", response.KeyCount); Console.WriteLine("Object is:");
foreach (S3Object o_value in response.S3Objects) { Console.WriteLine(o_value.Key); }
} catch (AmazonS3Exception e) { Console.WriteLine(e.Data); throw; } catch (Exception e) { Console.WriteLine(e); throw; } } } } |