Guzzle get file and forward it

前端 未结 1 850
一生所求
一生所求 2021-02-06 11:36

I have a web-service that gets a file and returns it to the user (based on Symfony). Ever since I used curl to do this.

I just found guzzlehttp and it seems great. How

相关标签:
1条回答
  • 2021-02-06 12:12
    public function streamAction()
    {
         $response = $client->request(
            'GET', 'http://httpbin.org/stream-bytes/1024', ['stream' => true]
         );
    
         $body = $response->getBody();
    
         $response = new StreamedResponse(function() use ($body) {
             while (!$body->eof()) {
                 echo $body->read(1024);
             }
         });
    
         $response->headers->set('Content-Type', 'text/xml');
    
         return $response;
    }
    
    0 讨论(0)
提交回复
热议问题