Amazon.S3.AmazonS3Client.GetObjectAsync C# (CSharp) Method

GetObjectAsync() public method

Initiates the asynchronous execution of the GetObject operation.
public GetObjectAsync ( GetObjectRequest request, System cancellationToken = default(CancellationToken) ) : Task
request GetObjectRequest Container for the necessary parameters to execute the GetObject operation.
cancellationToken System /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. ///
return Task
        public Task<GetObjectResponse> GetObjectAsync(GetObjectRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetObjectRequestMarshaller();
            var unmarshaller = GetObjectResponseUnmarshaller.Instance;

            return InvokeAsync<GetObjectRequest,GetObjectResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }

Same methods

AmazonS3Client::GetObjectAsync ( string bucketName, string key, System cancellationToken = default(CancellationToken) ) : Task
AmazonS3Client::GetObjectAsync ( string bucketName, string key, string versionId, System cancellationToken = default(CancellationToken) ) : Task
AmazonS3Client::GetObjectAsync ( GetObjectRequest request, GetObjectResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
AmazonS3Client::GetObjectAsync ( string bucketName, string key, GetObjectResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
AmazonS3Client::GetObjectAsync ( string bucketName, string key, string versionId, GetObjectResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void

Usage Example

        public async Task UploadDataFileAsync(string data, string storageKeyId, string storageSecret, string region)
        {
            var regionIdentifier = RegionEndpoint.GetBySystemName(region);
            using (var client = new AmazonS3Client(storageKeyId, storageSecret, regionIdentifier))
            {
                try
                {
                    var putRequest1 = new PutObjectRequest
                    {
                        BucketName = AwsBucketName,
                        Key = AwsBucketFileName,
                        ContentBody = data,
                        ContentType = "application/json"
                    };

                    await client.PutObjectAsync(putRequest1);
                }
                catch (AmazonS3Exception amazonS3Exception)
                {
                    if (amazonS3Exception.ErrorCode != null &&
                        (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                    {
                        throw new SecurityException("Invalid Amazon S3 credentials - data was not uploaded.", amazonS3Exception);
                    }

                    throw new HttpRequestException("Unspecified error attempting to upload data: " + amazonS3Exception.Message, amazonS3Exception);
                }

                var response = await client.GetObjectAsync(AwsBucketName, AwsBucketFileName);
                using (var reader = new StreamReader(response.ResponseStream))
                {
                    Debug.WriteLine(await reader.ReadToEndAsync());
                }
            }
        }
All Usage Examples Of Amazon.S3.AmazonS3Client::GetObjectAsync
AmazonS3Client