-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF export has wrong MIME type #1976
Comments
Could you clarify what you mean by...
Thanks |
If the file needs to be uploaded on another website, where the form validates the file type with |
So do you have this automated somehow? |
No, I found that by chance. I used the file to test a form of a website I work on and thought that the form broke but instead it uses the said method and fails to validate the file. I haven't tested it with other forms on other sites, but if they do check the MIME type and don't rely only on checking the file extension (which is not a safe way), it will fail there too. In any case the MIME type should match with the file suffix to prevent any possible errors. |
I believe that mime type is used to force the download of the PDF. |
Sorry, I don't understand your point. What are you suggesting? |
I mean the current set-up using "application/octet-stream" is intended, as we wanted the PDF to download in a browser, not open in the browser. Happy to have a discussion here to determine if any changes are required. |
There is a way to preserve the correct application/pdf MIME Type while still having the browser download the file. It involves setting the Content-Disposition header value to attachment. Here's how it is managed in barryvdh/laravel-dompdf: /**
* Make the PDF downloadable by the user
*/
public function download(string $filename = 'document.pdf'): Response
{
$output = $this->output();
$fallback = $this->fallbackName($filename);
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => HeaderUtils::makeDisposition('attachment', $filename, $fallback),
'Content-Length' => strlen($output),
]);
}
/**
* Return a response with the PDF to show in the browser
*/
public function stream(string $filename = 'document.pdf'): Response
{
$output = $this->output();
$fallback = $this->fallbackName($filename);
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => HeaderUtils::makeDisposition('inline', $filename, $fallback),
]);
} I tried to look at Lunar's source code for the PDF generation, but can't seem to find where the 'application/octet-stream' Content-Type is defined. If you can point me in the right direction I'd be happy to look at that issue. |
Expected Behaviour:
Exported pdf file should have MIME type "application/pdf".
Actual Behaviour:
MIME type is "application/octet-stream". This results in validation errors on other web forms.
Steps To Reproduce:
Go on "Orders". Select an order. Download order as PDF. Check MIME type with online tools.
The text was updated successfully, but these errors were encountered: