Ejemplo n.º 1
0
        // If-Modified-Since                    OR 304
        // If-None-Match        -- ETag         OR 304
        public async Task <IBlobResult> GetAsync(string key, GetBlobOptions options)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            int       retryCount = 0;
            Exception lastException;

            do
            {
                if (retryCount > 0)
                {
                    await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false);
                }

                try
                {
                    var request = ConstructGetRequest(key, options);

                    return(await client.GetObjectAsync(request).ConfigureAwait(false));
                }
                catch (S3Exception ex) when(ex.IsTransient)
                {
                    lastException = ex;
                }

                retryCount++;
            }while (retryPolicy.ShouldRetry(retryCount));

            throw lastException;
        }
Ejemplo n.º 2
0
        private GetObjectRequest ConstructGetRequest(string key, GetBlobOptions options)
        {
            var request = new GetObjectRequest(
                host: client.Host,
                bucketName: bucketName,
                key: key
                );

            if (options.IfModifiedSince is DateTimeOffset ifModifiedSince)
            {
                request.IfModifiedSince = ifModifiedSince;
            }

            if (options.EncryptionKey is byte[] encryptionKey)
            {
                request.SetCustomerEncryptionKey(new ServerSideEncryptionKey(encryptionKey));
            }

            if (options.IfNoneMatch is string ifNoneMatch)
            {
                request.IfNoneMatch = ifNoneMatch;
            }

            if (options.Range is ByteRange range)
            {
                request.SetRange(range.Start, range.End);
            }

            if (options.BufferResponse)
            {
                request.CompletionOption = HttpCompletionOption.ResponseContentRead;
            }

            return(request);
        }
Ejemplo n.º 3
0
        public async Task <IBlobResult> GetAsync(string key, GetBlobOptions options)
        {
            Ensure.NotNullOrEmpty(key, nameof(key));

            // TODO: Support blob options

            return(await client.GetObjectAsync(new GetObjectRequest(name, key)));
        }
Ejemplo n.º 4
0
        // If-Modified-Since                    OR 304
        // If-None-Match        -- ETag         OR 304
        public async Task <IBlobResult> GetAsync(string key, GetBlobOptions options)
        {
            #region Preconditions

            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            #endregion

            var request = new GetObjectRequest(
                host: client.Host,
                bucketName: bucketName,
                objectName: key
                );

            if (options.IfModifiedSince != null)
            {
                request.IfModifiedSince = options.IfModifiedSince;
            }

            if (options.EncryptionKey != null)
            {
                request.SetCustomerEncryptionKey(new ServerSideEncryptionKey(options.EncryptionKey));
            }

            if (options.IfNoneMatch != null)
            {
                request.IfNoneMatch = options.IfNoneMatch;
            }

            if (options.Range != null)
            {
                request.SetRange(options.Range.Value.Start, options.Range.Value.End);
            }

            if (options.BufferResponse)
            {
                request.CompletionOption = HttpCompletionOption.ResponseContentRead;
            }

            return(await client.GetObjectAsync(request).ConfigureAwait(false));
        }
Ejemplo n.º 5
0
        // If-Modified-Since                    OR 304
        // If-None-Match        -- ETag         OR 304

        public Task <IBlobResult> GetAsync(string key, GetBlobOptions options)
        {
            return(GetAsync(key, options, default));
        }