Jump to content

$files->send() Iphone error Cannot parse response


Recommended Posts

Posted

Facing a strange issue with $files->send() method creating this error only on Iphone Safari: "Cannot parse response". On all other clients it is working fine.

I am creating a pdf with @bernhard's RockPdf module (which basically is a wrapper around Mpdf library) and sending it for download to browser

$pdf = $modules->get('RockPdf');
// ...
$mpdf = $pdf->mpdf;
// ...
$mpdf->WriteHTML($header . $job->render(array('noLinks' => true))); // send $options['noLinks'] for pdf output to not render as links
$filename = $input->urlSegment1 . '.pdf';
$saved = $pdf->save($input->urlSegment1 . '.pdf');
if (isset($saved) && $saved->path && file_exists($saved->path)) {
    try {
        $files->send($saved->path, array('exit' => true));
        unlink($saved->path);
    } catch (\Throwable $th) {
        $log->save('pdfdownloads', $th->getMessage());
    }
}

When using Mpdf's native Output method, the rror does not occur

$pdf = $modules->get('RockPdf');
// ...
$mpdf = $pdf->mpdf;
// ...
$mpdf->WriteHTML($header . $job->render(array('noLinks' => true)));
$filename = $input->urlSegment1 . '.pdf';
try {
    $output = $mpdf->Output($filename, \Mpdf\Output\Destination::DOWNLOAD); // send to browser
} catch (\Throwable $th) {
    $log->save('pdfdownloads', $th->getMessage());
}
exit();

Since PDF generation and Mpdf's native Output method are working fine it seems that $files->send() is the culprit here.

Honestly, I have no idea what could cause such a behavior only on Iphone's Safari.

Any insights by someone who has more background knowledge on this would be much appreciated.

Posted
7 hours ago, Zeka said:

Hi @gebeer Not sure that this issue is PW relative.

Take a look at this thead on apple discussions: https://discussions.apple.com/thread/252479616

Thank you. I had googled but din't find that link which is quite enlightening. Seems like Mpdf's Output method sets different headers than $files->send() does. I will check what headers are set exactly and can then amend the $files->send() method using the headers option to pass the headers that Safari likes.
Cheers!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...