0

I have an Elixir/Phoenix crud app that serves some static files.

The file names are likely to contain (german) umlauts and I want to preserve them.

First I just responded with the file to the :show route of the upload but this had the unwanted effect that the filename at the downloading client would be the uploads id (e.g. 1 or 123).

To change that I switched to serving the files via a static plug. That worked well on Chrome and Firefox but today I noticed that it doesn't on Safari. On Safari I just get Page not found.

For me it seems like Safari doesn't encode the umlauts. Is this a bug in Safari? How do I work around that?

Here is a link to a page of the app that contains such a link: https://sozialoekonomie.klausurenarchiv.de/courses/21/instructors/25/uploads

On Safari the link of the file is: https://sozialoekonomie.klausurenarchiv.de/data/Makroökonomie/Pfannkuche/1474905178102463842/Makroökonomie%20Pfannekuche%20SoSe%2015%20mit%20Lösung%201,3.pdf

While on Chrome/Firefox the file uri is: https://sozialoekonomie.klausurenarchiv.de/data/Makro%C3%B6konomie/Pfannkuche/1474905178102463842/Makroo%CC%88konomie%20Pfannekuche%20SoSe%2015%20mit%20Lo%CC%88sung%201,3.pdf

fahrradflucht
  • 1,563
  • 3
  • 14
  • 22
  • That file's name seems to be in non-NFC-normalized form and it looks like Safari is normalizing it: http://www.lookout.net/2012/03/unicode-normalization-in-urls.html Can you try creating a file with NFC normalized filename to see if it works? E.g. copy paste this `fóó.txt`. – Dogbert Oct 09 '16 at 14:50
  • @Dogbert While trying this I noticed that I can't reproduce this locally on my mac at all. Here it works in all browsers as intended. Anyway: `fóó.txt` breaks in production (on Safari) as well. (Thats on Linux obvisously) – fahrradflucht Oct 09 '16 at 15:25
  • Okay there is definitely something strange going on. I ran the app in a Docker container and was able to reproduce it locally. Ran `URI.encode` on the URI and now it works (locally for now) in Chrome, Safari and Firefox. However: If I copy the URI of the file and past it again Safari still won't work. I think it does some encoding it shouldn't O.o – fahrradflucht Oct 09 '16 at 17:47
  • Phoenix's `send_attachment` might be relevant here. I think it allows you to set a different name for the file when sending it as a downloadable item. This would allow you to keep a generic english name at the back and set your desired german name when sending it as a download. – Sheharyar Oct 09 '16 at 18:09
  • @Sheharyar your comment made me think that Phoenix already has a `send_attachment` function [which is not the case](https://github.com/phoenixframework/phoenix/issues/1786). I'm also a little bit opposed to this solution because I kind of like the fact that users are able to view PDFs in desktop browsers without a save/open dialog. – fahrradflucht Oct 09 '16 at 19:06
  • The Content Disposition thing seems to have its own Utf8 issues anyway: http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http – fahrradflucht Oct 09 '16 at 20:53

0 Answers0