Download and save file from Amazon S3

Hi,

I am following Amazon’s tutorial on S3 but I cannot download file and save it to Streaming Resources. Instead I am downloading file content.

ResultText.text = string.Format("fetching {0} from bucket {1}", SampleFileName, S3BucketName);
        Client.GetObjectAsync(S3BucketName, SampleFileName, (responseObj) =>
        {
            string data = null;
            var response = responseObj.Response;
            if (response.ResponseStream != null)
            {
                using (StreamReader reader = new StreamReader(response.ResponseStream))
                {
                    data = reader.ReadToEnd();
                }

                ResultText.text += "

";
ResultText.text += data;
}
});

I understand that I should convert the response.ResponseStream into File but I tried many different solutions and I could not make it working.

if (response.ResponseStream != null)
{
using (var fs = System.IO.File.Create(@“c:\some-folder\file-name.ext”))
{
byte buffer = new byte[81920];
int count;
while ((count = response.ResponseStream.Read(buffer, 0, buffer.Length)) != 0)
fs.Write(buffer, 0, count);
fs.Flush();
}
}