Hello!
I'm having serious trouble downloading files that I've generated. Right now I'm using maatwebsite/laravel-excel to generate excel docs and everything works great until I try and download the file!
Here is the function I created that generates my file:
public function generateFileForInvoice($withholdingInvoice)
{
/** @var LaravelExcelWriter $file */
$file = Excel::create($withholdingInvoice->name, function ($excel) use ($withholdingInvoice) {
/** @var LaravelExcelWriter $excel */
$excel->sheet('Withholdings', function ($sheet) use ($withholdingInvoice) {
/** @var \Maatwebsite\Excel\Excel $sheet */
$sheet->loadView('withholding.invoice', ['withholdingInvoice' => $withholdingInvoice]);
});
$excel->sheet('Totals', function ($sheet) use ($withholdingInvoice) {
/** @var \Maatwebsite\Excel\Excel $sheet */
$sheet->loadView('withholding.totals', ['withholdingInvoice' => $withholdingInvoice]);
});
});
$file->store('xls')->download();
}
When I hit my endpoint it download a file but it is all garbled and busted and what not.
The crazy part is that the file that gets generated looks perfect if I just open it from the file system where i store it (developing locally).
This has lead me to believe that my headers are messed up or something but I'm fairly certain they are all correct.. this is what I have:
Cache-Control:cache, must-revalidate
Connection:keep-alive
Content-Disposition:attachment; filename="1_2017-01-01.xls"
Content-Type:application/vnd.ms-excel; charset=UTF-8
Date:Fri, 13 Jan 2017 08:27:05 GMT
Expires:Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified:Fri, 13 Jan 2017 08:27:05
Pragma:public
Server:nginx/1.10.0 (Ubuntu)
Transfer-Encoding:chunked
I've been messing with this stuff trying to get it to work for awhile now and any help would be appreciated. Another tactic I'm trying is to use the built in laravel function for downloading the file...
return response()->download($filePath, $filename, $headers);
So I know the file is already generated properly.. I just need to figure out a way to download it through browser where it won't be garbled...
As you can see I can pass in custom headers etc so any tips would be appreciated.
Thanks!