Estev's avatar
Level 2

Call to undefined method \BinaryFileResponse::header()

HI,

I tried to send a download response but i get this error :

Call to undefined method Symfony\\Component\\HttpFoundation\\BinaryFileResponse::header()

My code :

$file = storage_path('exports/file.xls');
return response()->download($file);

I'm using :

lumen 5.3 with dingo and JWT support.

Thank you.

0 likes
2 replies
Estev's avatar
Level 2

The problem is probably in the cors middleware:

protected function addCorsHeaders($request, $response)
    {


        foreach ([
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Max-Age' => (60 * 60 * 24),
            'Access-Control-Allow-Headers' => $request->header('Access-Control-Request-Headers'),
            'Access-Control-Allow-Methods' => $request->header('Access-Control-Request-Methods')
                ?: 'GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS',
            'Access-Control-Allow-Credentials' => 'true',
        ] as $header => $value) {
            $response->header($header, $value);
        }

        return $response;
    }

Estev's avatar
Level 2

I didn't find a solution for that. I moved to s3 and generate a presigned url

Please or to participate in this conversation.