Skip to content
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

[BUG] New Response in downloadAction puts additional HTML into download files #35

Closed
Bunnyfield opened this issue May 28, 2024 · 3 comments
Labels

Comments

@Bunnyfield
Copy link

With 21e4c62 the old way of providing a download file before doing an exit() has been replaced with a response created by the responseFactory.

Since Extbase does not focus on that response only, there is additional HTML content written into the file stream, creating broken download files with binary code surrounded by HTML.

According to the core docs, there should be an exception to avoid that behaviour:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Controller/ActionController.html#stop-further-processing-in-a-controller-s-action

Changing the return to

$response = $this->responseFactory->createResponse()
  ->withHeader('Content-Type', $cType)
  ->withHeader('Pragma', 'public')
  ->withHeader('Expires', '-1')
  ->withHeader('Cache-Control', 'public')
  ->withHeader('Content-Disposition', 'attachment; filename="' . $fileNameValid . '"')
  ->withHeader('Content-Length', $fileLen)
  ->withBody($this->streamFactory->createStreamFromFile($privateUri));

throw new PropagateResponseException($response, 200);

creates download files properly.

@Bunnyfield Bunnyfield added the bug label May 28, 2024
@Kephson
Copy link
Owner

Kephson commented Jun 5, 2024

Thank you very much Jo, I will check and implement it.

@SicorDev
Copy link

SicorDev commented Jan 9, 2025

I can confirm the problem, as well as the suggested solution. It just seems that the full page is unnecessarily rendered before it switches to the downloaded PDF. Observed in Firefox with the Exception code as above. Don't forget to add the "use" statement for the exception.

@Kephson
Copy link
Owner

Kephson commented Jan 9, 2025

Closed with the newest release 4.0.1: https://github.com/Kephson/reint_downloadmanager/releases/tag/4.0.1 and the commit 75403b2

@Kephson Kephson closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants