title: How to download file using guzzle and forward it to response without saving locally
body: <p>I'm using Laravel and I want to get files from api (with providing token and some headers) then forward it directly to the response without saving the file locally.</p>
  <p>Currently I'm doing it like this:</p>
  <pre><code>$response = $client-&gt;get($requestUrl, [
          'query' =&gt; [
              'hash' =&gt; $hash
          ],
          'headers' =&gt; [
              '_token_' =&gt; $oauthConfig['api_token'],
              '_token_issuer_' =&gt; 1
          ],
          'stream' =&gt; true,
      ]);
  
      $type = $response-&gt;getHeader('Content-Type')[0];
      $body = $response-&gt;getBody();
  
      $response = new StreamedResponse(function () use ($body) {
          while (!$body-&gt;eof()) {
              echo $body-&gt;read(1024);
          }
      });
  
      $response-&gt;headers-&gt;set('Content-Type', $type);
  
      return $response;
  </code></pre>
  <p>But I'm getting this exception:</p>
  <pre><code>LogicException
  The content cannot be set on a StreamedResponse instance.
  </code></pre>
  <p>Any help / guidance is greatly appreciated!
  Thanks.</p>