- Home /
 
               Question by 
               lennyrogal · Mar 01, 2018 at 06:56 PM · 
                filedownloadamazonstreamreader  
              
 
              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 += "\n";
                 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.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by lennyrogal · Mar 01, 2018 at 07:52 PM
 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();
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
error when open downloaded file 0 Answers
Download .unity3D file from server with WWW - zero length 1 Answer
Saving Local Data through WWW 1 Answer
[Android] Download file.cs from Url & use it instead of original script. 1 Answer
Why can't we download instead of opening files in our Web Browser? 6 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                