Beispiel #1
0
        public static async Task <GetObjectMetadataResponse> ObjectMetadataAsync(this S3Helper s3,
                                                                                 string bucketName,
                                                                                 string key,
                                                                                 bool throwIfNotFound = true,
                                                                                 CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var metadata = await s3.GetObjectMetadata(bucketName : bucketName, key : key, cancellationToken : cancellationToken);

                return(metadata);
            }
            catch (Exception ex)
            {
                if (!throwIfNotFound)
                {
                    if (ex is Amazon.S3.AmazonS3Exception &&
                        (ex as Amazon.S3.AmazonS3Exception).StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(null);
                    }
                }

                throw;
            }
        }
Beispiel #2
0
        public static async Task <bool> ObjectExistsAsync(this S3Helper s3,
                                                          string bucketName,
                                                          string key,
                                                          CancellationToken cancellationToken = default(CancellationToken))
        {
            try
            {
                var metadata = await s3.GetObjectMetadata(bucketName : bucketName, key : key, cancellationToken : cancellationToken);

                return(true);
            }
            catch (Exception ex)
            {
                if (ex is Amazon.S3.AmazonS3Exception &&
                    (ex as Amazon.S3.AmazonS3Exception).StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(false);
                }

                throw;
            }
        }