本文整理汇总了C#中Amazon.S3.Model.GetObjectMetadataRequest类的典型用法代码示例。如果您正苦于以下问题:C# GetObjectMetadataRequest类的具体用法?C# GetObjectMetadataRequest怎么用?C# GetObjectMetadataRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetObjectMetadataRequest类属于Amazon.S3.Model命名空间,在下文中一共展示了GetObjectMetadataRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LastWriteTime
public DateTime LastWriteTime(string id)
{
using (var client = SetupClient())
{
try {
var request = new GetObjectMetadataRequest().WithBucketName(BucketName).WithKey(id);
var response = client.GetObjectMetadata(request);
var date = response.LastModified;
var lastwrite = response.Metadata[LastWriteTimeKey];
return DateTime.Parse(lastwrite);
}
catch
{
return DateTime.MinValue;
}
}
}
示例2: Execute
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>True if the task executed successfully, false otherwise.</returns>
public override bool Execute()
{
bool exists = false;
GetObjectMetadataRequest request = new GetObjectMetadataRequest()
.WithBucketName(BucketName)
.WithKey(this.Key);
try
{
using (GetObjectMetadataResponse response = Client.GetObjectMetadata(request))
{
exists = true;
}
}
catch (AmazonS3Exception ex)
{
if (ex.StatusCode != HttpStatusCode.NotFound || !"NoSuchKey".Equals(ex.ErrorCode, StringComparison.OrdinalIgnoreCase))
{
throw;
}
}
Exists = exists;
return true;
}
示例3: BucketRegionTestRunner
public BucketRegionTestRunner(bool useSigV4, bool useSigV4SetExplicitly = false)
{
originalUseSignatureVersion4 = AWSConfigsS3.UseSignatureVersion4;
originalUseSigV4SetExplicitly = GetAWSConfigsS3InternalProperty();
AWSConfigsS3.UseSignatureVersion4 = useSigV4;
SetAWSConfigsS3InternalProperty(useSigV4SetExplicitly);
CreateAndCheckTestBucket();
if (TestBucketIsReady)
{
GetObjectMetadataRequest = new GetObjectMetadataRequest()
{
BucketName = TestBucket.BucketName,
Key = TestObjectKey
};
PutObjectRequest = new PutObjectRequest()
{
BucketName = TestBucket.BucketName,
Key = TestObjectKey,
ContentBody = TestContent
};
PreSignedUrlRequest = new GetPreSignedUrlRequest
{
BucketName = BucketName,
Key = BucketRegionTestRunner.TestObjectKey,
Expires = DateTime.Now.AddHours(1)
};
}
}
示例4: CreateGetObjectMetadataRequest
protected internal virtual GetObjectMetadataRequest CreateGetObjectMetadataRequest(string bucket, string path)
{
var request = new GetObjectMetadataRequest
{
BucketName = bucket,
Key = path,
};
return request;
}
示例5: OnFilePublished
/// <summary>
/// Invoked when the publisher has published a file.
/// </summary>
/// <param name="path">The local path of the file that was published.</param>
/// <param name="objectKey">The object key the file was published to.</param>
/// <param name="withGzip">A value indicating whether the file was GZipped prior to publishing.</param>
public void OnFilePublished(string path, string objectKey, bool withGzip)
{
if (this.assertPublished)
{
GetObjectMetadataRequest request = new GetObjectMetadataRequest()
.WithBucketName(BucketName)
.WithKey(objectKey);
using (GetObjectMetadataResponse response = Client.GetObjectMetadata(request))
{
Assert.AreEqual(MimeType.FromCommon(objectKey).ContentType, response.ContentType);
if (withGzip)
{
Assert.AreEqual("gzip", response.Headers["Content-Encoding"]);
}
}
}
}
示例6: FileExists
bool FileExists(string key)
{
try
{
var request = new GetObjectMetadataRequest()
.WithBucketName(bucket)
.WithKey(key);
var response = s3client.GetObjectMetadata(request);
return true;
}
catch(AmazonS3Exception ex)
{
if(ex.StatusCode == HttpStatusCode.NotFound)
{
return false;
}
throw;
}
}
示例7: Test_Blob_Properties_Updated_Async
public async void Test_Blob_Properties_Updated_Async()
{
var container = GetRandomContainerName();
var blobName = GenerateRandomName();
var contentType = "image/jpg";
var newContentType = "image/png";
var data = GenerateRandomBlobStream();
await CreateNewObjectAsync(container, blobName, data, false, contentType);
await _provider.UpdateBlobPropertiesAsync(container, blobName, new BlobProperties
{
ContentType = newContentType,
Security = BlobSecurity.Public
});
var objectMetaRequest = new GetObjectMetadataRequest()
{
BucketName = Bucket,
Key = container + "/" + blobName
};
var props = await _client.GetObjectMetadataAsync(objectMetaRequest);
Assert.Equal(props.Headers.ContentType, newContentType);
var objectAclRequest = new GetACLRequest()
{
BucketName = Bucket,
Key = container + "/" + blobName
};
var acl = await _client.GetACLAsync(objectAclRequest);
var isPublic = acl.AccessControlList.Grants
.Where(x => x.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers").Count() > 0;
Assert.True(isPublic);
}
示例8: GetFileInfoAsync
public async Task<FileSpec> GetFileInfoAsync(string path) {
using (var client = CreateClient()) {
var req = new GetObjectMetadataRequest {
BucketName = _bucket,
Key = path.Replace('\\', '/')
};
try {
var res = await client.GetObjectMetadataAsync(req).AnyContext();
if (!res.HttpStatusCode.IsSuccessful())
return null;
return new FileSpec {
Size = res.ContentLength,
Created = res.LastModified,
Modified = res.LastModified,
Path = path
};
} catch (AmazonS3Exception) {
return null;
}
}
}
示例9: Exists
public virtual async Task<QueryResult<bool>> Exists(string namePath)
{
bool exists = false;
bool hasExceptions = false;
try
{
IAmazonS3 client = GetS3Client();
GetObjectMetadataRequest request = new GetObjectMetadataRequest()
{
BucketName = Settings.BucketName,
Key = namePath
};
GetObjectMetadataResponse response
= await client.GetObjectMetadataAsync(request);
exists = true;
}
catch (AmazonS3Exception ex)
{
if(ex.StatusCode == System.Net.HttpStatusCode.NotFound)
{
exists = false;
}
else
{
_logger.Exception(ex);
hasExceptions = true;
}
}
return new QueryResult<bool>(exists, hasExceptions);
}
示例10: FileExists
public bool FileExists(string virtualPath) {
var request = new GetObjectMetadataRequest()
.WithBucketName(this.bucketName)
.WithKey(FixPathForS3(virtualPath));
try {
using (this.s3.GetObjectMetadata(request)) { }
} catch (AmazonS3Exception) {
return false;
}
return true;
}
示例11: DirectoryExists
public bool DirectoryExists(string virtualPath) { // ~/upload/28/
virtualPath = FixPathForS3(virtualPath) + EmptyFilename;
var request = new GetObjectMetadataRequest()
.WithBucketName(this.bucketName)
.WithKey(virtualPath);
try {
using (this.s3.GetObjectMetadata(request)) { }
} catch (AmazonS3Exception) {
return false;
}
return true;
}
示例12: GetObjectMetadataAsync
/// <summary>
/// Initiates the asynchronous execution of the GetObjectMetadata operation.
/// <seealso cref="Amazon.S3.IAmazonS3.GetObjectMetadata"/>
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the GetObjectMetadata operation.</param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
/// <returns>The task object representing the asynchronous operation.</returns>
public Task<GetObjectMetadataResponse> GetObjectMetadataAsync(GetObjectMetadataRequest request, CancellationToken cancellationToken = default(CancellationToken))
{
var marshaller = new GetObjectMetadataRequestMarshaller();
var unmarshaller = GetObjectMetadataResponseUnmarshaller.GetInstance();
return Invoke<IRequest, GetObjectMetadataRequest, GetObjectMetadataResponse>(request, marshaller, unmarshaller, signer, cancellationToken);
}
示例13: GetObjectMetadata
/// <summary>
/// Returns information about a specified object.
/// </summary>
/// <remarks>
/// Retrieves information about a specific object or object size, without actually fetching the object itself.
/// This is useful if you're only interested in the object metadata, and don't want to waste bandwidth on the object data.
/// The response is identical to the GetObject response, except that there is no response body.
/// </remarks>
/// <param name="request">Container for the necessary parameters to execute the GetObjectMetadata service method on AmazonS3.</param>
/// <returns>The response from the HeadObject service method, as returned by AmazonS3.</returns>
public GetObjectMetadataResponse GetObjectMetadata(GetObjectMetadataRequest request)
{
var task = GetObjectMetadataAsync(request);
try
{
return task.Result;
}
catch(AggregateException e)
{
throw e.InnerException;
}
}
示例14: BeginGetObjectMetadata
/// <summary>
/// Initiates the asynchronous execution of the GetObjectMetadata operation.
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the GetObjectMetadata operation on AmazonS3Client.</param>
/// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
/// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
/// procedure using the AsyncState property.</param>
///
/// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetObjectMetadata
/// operation.</returns>
public IAsyncResult BeginGetObjectMetadata(GetObjectMetadataRequest request, AsyncCallback callback, object state)
{
var marshaller = new GetObjectMetadataRequestMarshaller();
var unmarshaller = GetObjectMetadataResponseUnmarshaller.Instance;
return BeginInvoke<GetObjectMetadataRequest>(request, marshaller, unmarshaller,
callback, state);
}
示例15: GetObjectMetadataAsync
/// <summary>
/// Initiates the asynchronous execution of the GetObjectMetadata operation.
/// </summary>
///
/// <param name="request">Container for the necessary parameters to execute the GetObjectMetadata operation.</param>
/// <param name="cancellationToken">
/// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
/// </param>
/// <returns>The task object representing the asynchronous operation.</returns>
public Task<GetObjectMetadataResponse> GetObjectMetadataAsync(GetObjectMetadataRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
{
var marshaller = new GetObjectMetadataRequestMarshaller();
var unmarshaller = GetObjectMetadataResponseUnmarshaller.Instance;
return InvokeAsync<GetObjectMetadataRequest,GetObjectMetadataResponse>(request, marshaller,
unmarshaller, cancellationToken);
}