예제 #1
0
        /// <summary>
        /// Gets object information - Without file data
        /// </summary>
        /// <param name="objectId">Object Id</param>
        /// <param name="bucketName">Bucket name - Optional if passed throuhg constructor</param>
        /// <returns>Returns object information and metadata</returns>
        /// <exception cref="EndpointUnreachableException">Thrown when S3 endpoint is unreachable.</exception>
        /// <exception cref="ObjectNotFoundException">Thrown when object is not found.</exception>
        /// <exception cref="S3BaseException">Thrown when exception is not handled.</exception>
        public async Task <S3Object> GetObjectInfo(string objectId)
        {
            var s3Obj      = BucketHelper.ExtractObjectInfo(objectId);
            var bucket     = s3Obj.bucketName?.ToLower() ?? _bucketName;
            var objectName = s3Obj.objectName;

            S3Object result = null;

            try
            {
                result = await _requestRetryPolicy.ExecuteAsync(async() =>
                {
                    var response = await _objectOperationsClient.StatObjectAsync(bucket, objectName);

                    if (response == null)
                    {
                        throw new Exceptions.ObjectNotFoundException(objectName, bucket);
                    }

                    return(new S3Object(response.ObjectName, bucket, response.Size, response.ETag, response.ContentType, response.MetaData, null));
                });
            }
            catch (MinioException ex) when(ex is ConnectionException ||
                                           ex is InternalServerException ||
                                           ex is InternalClientException ||
                                           ex is InvalidEndpointException
                                           )
            {
                throw new EndpointUnreachableException(_endpoint, ex.ToString());
            }
            catch (S3BaseException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new S3BaseException(ex.Message, ex.ToString());
            }

            return(result);
        }