viritin / flow-viritin

Viritin inspired project for Vaadin Flow
Other
39 stars 15 forks source link

Download not working on mobile Safari anymore #58

Closed timomeinen closed 2 months ago

timomeinen commented 2 months ago

Hi @mstahv,

in #45 I have raised a PR to add the Content-Type header in order to allow downloads on mobile safari iOS. Unfortunately, setting the header had been removed in commit e52f6589bf5722f72147a943cd2931e1c393b544 in this line for issue #49. I assume it was tested on macOS desktop Safari. The behaviour is different between mobile and desktop Safari. If Content-Type header is missing, mobile Safari will not honor file extension and instead adds a .html to the download filename making it impossible to download a e.g. PDF. In contrast, if header is missing on desktop Safari, the browser guesses mime type by file extension.

Please re-add the header again to enable downloads on mobile safari:

response.setHeader("Content-Type", contentTypeGenerator.getContentType());

Note: The @FunctionInterface ContentTypeGenerator still exists in the code, but the method getContentType is never called. This was hard to find, as my program continued to set the withContentTypeGenerator but the lambda itself was not called anymore.

Please see attached PR.

Thanks, Timo

mstahv commented 2 months ago

Thanks Timo, dropped it by accident when copy pasting another fix! 2.8.15 on its way to central.

Should start writing some tests for this and the upload component, second regression in short time 😬