本文整理汇总了C#中Amazon.S3.Model.GetObjectMetadataRequest.WithBucketName方法的典型用法代码示例。如果您正苦于以下问题:C# GetObjectMetadataRequest.WithBucketName方法的具体用法?C# GetObjectMetadataRequest.WithBucketName怎么用?C# GetObjectMetadataRequest.WithBucketName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.Model.GetObjectMetadataRequest
的用法示例。
在下文中一共展示了GetObjectMetadataRequest.WithBucketName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: objectSerial
public static void objectSerial(String filePath)
{
System.Console.WriteLine("\nhello,object!!");
NameValueCollection appConfig = ConfigurationManager.AppSettings;
AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
String bucketName = "chttest3";
String objectName = "hello";
//String filePath = "D:\\Visual Studio Project\\TestNetSDK\\TestNetSDK\\pic.jpg";
//PutBucket
System.Console.WriteLine("PutBucket: {0}\n",bucketName);
PutBucketResponse response = s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));
//PutObject
System.Console.WriteLine("PutObject!\n");
PutObjectRequest request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.WithKey(objectName);
request.WithFilePath(filePath);
PutObjectResponse PutResult = s3Client.PutObject(request);
System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult.ETag);
//HeadObject
System.Console.WriteLine("HeadObject!\n");
GetObjectMetadataResponse HeadResult = s3Client.GetObjectMetadata(new GetObjectMetadataRequest().WithBucketName(bucketName).WithKey(objectName));
System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult.ContentLength,HeadResult.ETag);
//GetObject
System.Console.WriteLine("GetObject!\n");
GetObjectResponse GetResult = s3Client.GetObject(new GetObjectRequest().WithBucketName(bucketName).WithKey(objectName).WithByteRange(1,15));
Stream responseStream = GetResult.ResponseStream;
StreamReader reader = new StreamReader(responseStream);
System.Console.WriteLine("Get Object Content:\n {0}\n", reader.ReadToEnd());
System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult.ETag);
//CopyObject
CopyObjectResponse CopyResult = s3Client.CopyObject(new CopyObjectRequest().WithSourceBucket(bucketName).WithSourceKey(objectName).WithDestinationBucket(bucketName).WithDestinationKey("hihi"));
System.Console.WriteLine("CopyObject: ETag: {0} \n",CopyResult.ETag);
//DeleteObject
System.Console.WriteLine("Delete Object!\n");
s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey(objectName));
s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey("hihi")); //copied object
//==============================jerry add ==============================
System.Console.WriteLine("Jerry Add!\n");
String objectName2 = "hello2";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("A", "ABC");
System.Console.WriteLine("PutObject!\n");
PutObjectRequest request2 = new PutObjectRequest();
request2.WithBucketName(bucketName);
request2.WithKey(objectName2);
request2.WithAutoCloseStream(true);
request2.WithCannedACL(S3CannedACL.BucketOwnerFullControl);
request2.WithContentBody("test");
request2.WithContentType("test/xml");
request2.WithGenerateChecksum(true);
request2.WithMD5Digest("CY9rzUYh03PK3k6DJie09g==");
request2.WithMetaData(nvc);
request2.WithWebsiteRedirectLocation("http://hicloud.hinet.net/");
PutObjectResponse PutResult2 = s3Client.PutObject(request2);
System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult2.ETag);
System.Console.WriteLine("GetObject!\n");
GetObjectRequest request3 = new GetObjectRequest();
request3.WithBucketName(bucketName);
request3.WithKey(objectName2);
request3.WithByteRange(1, 2);
DateTime datetime = DateTime.UtcNow;
// 似乎不支援 datetime
request3.WithModifiedSinceDate(datetime.AddHours(-1));
request3.WithUnmodifiedSinceDate(datetime.AddHours(1));
request3.WithETagToMatch(PutResult2.ETag);
request3.WithETagToNotMatch("notMatch");
GetObjectResponse GetResult2 = s3Client.GetObject(request3);
Stream responseStream2 = GetResult2.ResponseStream;
StreamReader reader2 = new StreamReader(responseStream2);
System.Console.WriteLine("Get Object Content(es):\n {0}\n", reader2.ReadToEnd());
System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult2.ETag);
System.Console.WriteLine("HeadObject!\n");
GetObjectMetadataRequest request4 = new GetObjectMetadataRequest();
request4.WithBucketName(bucketName);
request4.WithKey(objectName2);
DateTime datetime2 = DateTime.UtcNow;
// 似乎不支援 datetime
request4.WithModifiedSinceDate(datetime2.AddHours(-1));
request4.WithUnmodifiedSinceDate(datetime2.AddHours(1));
request4.WithETagToMatch(PutResult2.ETag);
request4.WithETagToNotMatch("notMatch");
GetObjectMetadataResponse HeadResult2 = s3Client.GetObjectMetadata(request4);
System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult2.ContentLength, HeadResult2.ETag);
CopyObjectRequest request5 = new CopyObjectRequest();
//.........这里部分代码省略.........
示例2: ObjectExists
public bool ObjectExists(Uri uri)
{
CheckUri(uri);
try
{
using (var client = CreateAmazonS3Client())
{
try
{
var absolutePath = HttpUtility.UrlDecode(uri.AbsolutePath);
var key = absolutePath.TrimStart('/');
var request = new GetObjectMetadataRequest();
request.WithBucketName(bucketName)
.WithKey(key);
using (client.GetObjectMetadata(request))
{
return true;
}
}
catch (AmazonS3Exception ex)
{
if (ex.StatusCode == HttpStatusCode.NotFound)
{
return false;
}
// Status not found - throw the exception.
throw;
}
}
}
catch (Exception e)
{
throw new StorageException(string.Format("Failed to check if object exists {0}.", uri), e);
}
}
示例3: GetFilesOnS3
private static void GetFilesOnS3(object state)
{
System.Console.WriteLine("Check Files on S3...");
ListObjectsResponse listObjectsResponse = _amazonS3Client.ListObjects(new ListObjectsRequest { BucketName = BucketName });
foreach (S3Object s3Object in listObjectsResponse.S3Objects)
{
FileInfo fileInfo = new FileInfo(Path.Combine(_folder, s3Object.Key));
if (fileInfo.Exists)
{
System.Console.WriteLine(s3Object.Key + " exist");
GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest();
getObjectMetadataRequest.WithBucketName(BucketName).WithKey(s3Object.Key);
GetObjectMetadataResponse getObjectMetadataResponse = _amazonS3Client.GetObjectMetadata(getObjectMetadataRequest);
//int dateCompare = DateTime.Compare(fileInfo.LastWriteTime., DateTime.Parse(getObjectMetadataResponse.Metadata["x-amz-meta-LWT"]));
int dateCompare = (int)(fileInfo.LastWriteTime - DateTime.Parse(getObjectMetadataResponse.Metadata["x-amz-meta-LWT"])).TotalSeconds;
if (dateCompare == 0)
{
System.Console.WriteLine("No difference, do nothing");
}
else if (dateCompare < 0)
{
System.Console.WriteLine("S3 is newer");
DownloadFile(s3Object);
}
else if (dateCompare > 0)
{
System.Console.WriteLine("FS is newer");
UploadFile(fileInfo);
}
}
else
{
System.Console.WriteLine(s3Object.Key + " doesn't exist");
DownloadFile(s3Object);
}
}
foreach (string file in Directory.GetFiles(_folder))
{
FileInfo fileInfo = new FileInfo(file);
if (!listObjectsResponse.S3Objects.Any(s => s.Key == fileInfo.Name))
{
UploadFile(fileInfo);
}
}
}