Open liepumartins opened 1 year ago
Laravel Vapor requires custom headers for binary file downloads. https://docs.vapor.build/1.0/projects/development.html#binary-responses
Attempting to do
return (new FastExcel($data))->download('name.xlsx');
will cause an error
Fatal error: Uncaught Exception: Error encoding runtime JSON response: Malformed UTF-8 characters, possibly incorrectly encoded in /var/task/vendor/laravel/vapor-core/src/Runtime/NotifiesLambda.php:49
I see that streamDownload() can take HTTP headers, but there is no way to pass them down from calling download(). https://github.com/rap2hpoutre/fast-excel/blob/c6d2b8b707b85f7c43028d3b4cc969388d8b6c17/src/Exportable.php#L68
streamDownload()
download()
Trying to extend the class and customize download method is not viable as many used methods are private.
download
This should work
public function download($path, callable $callback = null) { if (method_exists(response(), 'streamDownload')) { return response()->streamDownload(function () use ($path, $callback) { self::exportOrDownload($path, 'openToBrowser', $callback); }, null, ['X-Vapor-Base64-Encode' => 'True']); } self::exportOrDownload($path, 'openToBrowser', $callback); return ''; }
Laravel Vapor requires custom headers for binary file downloads. https://docs.vapor.build/1.0/projects/development.html#binary-responses
Attempting to do
will cause an error
I see that
streamDownload()
can take HTTP headers, but there is no way to pass them down from callingdownload()
. https://github.com/rap2hpoutre/fast-excel/blob/c6d2b8b707b85f7c43028d3b4cc969388d8b6c17/src/Exportable.php#L68Trying to extend the class and customize
download
method is not viable as many used methods are private.This should work