Search code examples
phplaraveldompdf

Laravel File Not Downloading


Yes I've read all the other questions before anyone marks it as a duplicate

I'm running Larvel 5.5

I installed https://github.com/barryvdh/laravel-dompdf laravel/dompdf

I'm trying to save a version of the users profile. It returns the correct response but I get no file downloaded, and I can't for the life of me figure out why

accept-ranges:none
cache-control:public
cf-ray:3e54e0dd7d5e778a-LAX
content-disposition:attachment; filename="Resume.pdf"
content-length:118499
content-type:application/pdf
date:Tue, 30 Jan 2018 13:46:45 GMT
expect-ct:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
last-modified:Tue, 30 Jan 2018 13:46:45 GMT
server:cloudflare
set-cookie:XSRF-TOKEN=eyJpdiI6IkVsUFdxVkpIZmpiSjNIOWpUXC9Xc3pBPT0iLCJ2YWx1ZSI6IkdYNDJEYXBnOGsrSFJDM3hPWFRpZlZEZDlYMVwvMitzQTJzcGloRGExSnpwXC9heVRMNVd1WUlkUHVacDBcL1Y2bWN5V1VuMzdPdHRNdmN1TUNmcHdnZThnPT0iLCJtYWMiOiJhNzA1ZmRmYjNkMGFjNWNkY2ZiNzg1MjhiOTYzM2Y5NjVmOTRmYmMzMmYzMzcwMThjNWFlMDM4YjMwNDRjNWU2In0%3D; expires=Tue, 30-Jan-2018 15:46:45 GMT; Max-Age=7200; path=/; domain=theareel.com
set-cookie:laravel_session=eyJpdiI6ImJURThTelFDc1Nvc1QyK3g1T1U1NkE9PSIsInZhbHVlIjoiUDRWMmxPdFlkaCswWHhGZGpPS2FiQThHdlQ3bVU3YXljQStlbUFEdlwvXC9IN2NYd1B0bGJxNlZGUFgrZDRMWGtJTkJEWFVkYXRiNWRxcXJCdXZtNTVsUT09IiwibWFjIjoiZjQyYWEzOTcxYTY4Y2RjMzljMTYyZDc0OWY2ZDQ3NWJkZmE3ZTNkNTBjNTFkN2ZlYTZiN2Y2NGYzN2RiOTM3OCJ9; expires=Tue, 30-Jan-2018 15:46:45 GMT; Max-Age=7200; path=/; domain=theareel.com; HttpOnly
status:200

I also get a HUGE string returned as a response, this is all stemming from this code

$User = Auth::user();
$PDF = PDF::loadView('downloadProfile', compact($User));
$PDF->save(public_path().'/'.Auth::user()->id.'resume.pdf');
return response()->download(public_path().'/'.Auth::user()->id.'resume.pdf', 'Resume.pdf');//->deleteFileAfterSend(true);

Any idea why it won't actually start the download? I've tried literally everything I can think of, setting the request headers, saving the file then downloading, skipping the saving part and just downloading it outright with

return $PDF->download('Resume.pdf');

They all return the correct response in the browser but it refuses to download anything

Thanks

  • Zach

Solution

  • To solve the problem:

    I was getting the file via JSON and returning it via JSON was the issue

    To fix it I created a GET route for the download to follow via GET /username/downloadPDF and returned the same and it downloads