PostObjectAsync() public method

Upload data to Amazon S3 using HTTP POST.
For more information,
public PostObjectAsync ( PostObjectRequest request, PostObjectResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
request PostObjectRequest Request object which describes the data to POST
callback PostObjectResponse>.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
Beispiel #1
0
 public static PostObjectResponse PostObjectHelper(AmazonS3Client client, string bucketName, string key, PostObjectRequestManipulator manipulator = null)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         PostObjectResponse r = null;
         Exception responseException = null;
         StreamWriter writer = new StreamWriter(stream);
         writer.Write(TestContent);
         writer.Flush();
         stream.Position = 0;
         AutoResetEvent ars = new AutoResetEvent(false);
         var request = new PostObjectRequest()
         {
             Bucket = bucketName,
             Key = key,
             InputStream = stream
         };
         if (manipulator != null)
         {
             manipulator(request);
         }
         client.PostObjectAsync(request, (response) =>
         {
             responseException = response.Exception;
             if (responseException == null)
             {
                 r = response.Response;
             }
             else
             {
                 Debug.LogWarning(new StreamReader((responseException as Amazon.Runtime.Internal.HttpErrorResponseException).Response.ResponseBody.OpenResponse()).ReadToEnd());
             }
             ars.Set();
         }, new AsyncOptions { ExecuteCallbackOnMainThread = false });
         ars.WaitOne();
         if (responseException != null)
         {
             throw responseException;
         }
         return r;
     }
 }