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

GetObjectAsync() public method

Retrieves objects from Amazon S3.
public GetObjectAsync ( string bucketName, string key, GetObjectResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
bucketName string A property of GetObjectRequest used to execute the GetObject service method.
key string A property of GetObjectRequest used to execute the GetObject service method.
callback GetObjectResponse>.AmazonServiceCallback An Action delegate that is invoked when the operation completes.
options AsyncOptions /// A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property. ///
return void
        public void GetObjectAsync(string bucketName, string key,  AmazonServiceCallback<GetObjectRequest, GetObjectResponse> callback, AsyncOptions options = null)
        {
            var request = new GetObjectRequest();
            request.BucketName = bucketName;
            request.Key = key;
            GetObjectAsync(request, callback, options);
        }

Same methods

AmazonS3Client::GetObjectAsync ( GetObjectRequest request, System cancellationToken = default(CancellationToken) ) : Task
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, 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