コード例 #1
0
ファイル: S3Bucket.cs プロジェクト: jweissBHG/Amazon
        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);
        }
コード例 #2
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));
        }