title: Laravel file downloaded from AWS S3 with Filesystem gets corrupted
body: <p>I am uploading files to Amazon S3 with Laravel filesystem. The upload process works great, however, when I download the files get corrupted. I have manually downloaded the files from the S3 bucket and that way the files don't get corrupted, so I figured that the problem is not the upload.</p>
  
  <p>I am uploading the files like this:</p>
  
  <pre><code>/**
   * Upload the file to Amazon S3.
   *
   * @param UploadedFile $file
   * @param $path
   * @return $this|bool
   */
  protected function upload(UploadedFile $file, $path)
  {
      $this-&gt;filename = $path . '/' . time() . '_' . str_replace(' ', '-', $file-&gt;getClientOriginalName());
  
      $disk = Storage::cloud();
  
      if ($disk-&gt;put($this-&gt;filename, fopen($file, 'r+'))) {
  
          $this-&gt;save();
  
          return $this;
      }
  
      return false;
  }
  </code></pre>
  
  <p>And to download I have tried this:</p>
  
  <pre><code>/**
   * @param Document $document
   * @return Response
   */
  public function download(Document $document)
  {
      $file = Storage::cloud()-&gt;get($document-&gt;path);
  
      $file_info = new finfo(FILEINFO_MIME_TYPE);
  
      return response($file, 200)-&gt;withHeaders([
          'Content-Type'        =&gt; $file_info-&gt;buffer($file),
          'Content-Disposition' =&gt; 'inline; filename="' . $document-&gt;name . '"'
      ]);
  }
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>/**
   * @param Document $document
   * @return Response
   */
  public function download(Document $document)
  {
      $stream = Storage::cloud()-&gt;getDriver()-&gt;readStream($document-&gt;path);
  
      $file = stream_get_contents($stream);
  
      $file_info = new finfo(FILEINFO_MIME_TYPE);
  
      return response($file, 200)-&gt;withHeaders([
          'Content-Type'        =&gt; $file_info-&gt;buffer($file),
          'Content-Disposition' =&gt; 'inline; filename="' . $document-&gt;name . '"'
      ]);
  }
  </code></pre>
  
  <p>With both download functions I get the files, however they become corrupted. Any help is appreciated!</p>