Amazon AWS SDK User's Guide Page 32

  • Download
  • Add to my manuals
  • Print
  • Page
    / 155
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 31
//
// You will need to use your own bucket name below in order
// to run this sample code.
//
PutObjectRequest request = new PutObjectRequest
{
BucketName = "PUT YOUR OWN EXISTING BUCKET NAME HERE",
Key = "Item",
ContentBody = "This is sample content..."
};
//
// additional example code
//
}
No Callback Specified
The following example code calls BeginPutObject, performs some work, then calls EndPutObject to
retrieve the service response.The call to EndPutObject is enclosed in a try block to catch any exceptions
that might have been thrown during the operation.
asyncResult = client.BeginPutObject(request, null, null);
while ( ! asyncResult.IsCompleted ) {
//
// Do some work here
//
}
try {
response = client.EndPutObject(asyncResult);
}
catch (AmazonS3Exception s3Exception) {
//
// Code to process exception
//
}
Simple Callback
This example assumes that the following callback function has been defined.
public static void SimpleCallback(IAsyncResult asyncResult)
{
Console.WriteLine("Finished PutObject operation with simple callback");
}
The following line of code calls BeginPutObject and specifies the above callback function. When the
PutObject operation completes, the callback function is called. The call to BeginPutObject specifies
null for the state parameter because the simple callback function does not access the AsyncState
property of the asyncResult parameter. Neither the calling code or the callback function call
EndPutObject. Therefore, the service response is effectively discarded and any exceptions that occur
during the operation are ignored.
asyncResult = client.BeginPutObject(request, SimpleCallback, null);
Version v2.0.0
28
AWS SDK for .NET Developer Guide
Asynchronous API for .NET 3.5
Page view 31
1 2 ... 27 28 29 30 31 32 33 34 35 36 37 ... 154 155

Comments to this Manuals

No comments