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; } }
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); } }