runserver MIME types on Windows

77 views
Skip to first unread message

Peter Marheine

unread,
Sep 25, 2020, 9:55:54 AM9/25/20
to Django developers (Contributions to Django itself)
Hi list,

When developing on Windows I was recently bit by Windows providing wrong MIME type mappings for file names. I filed a ticked for that which has more details [1], but given it was summarily closed as not a bug in Django I wanted to see if there were broader opinions on the matter.


I don't disagree with the argument that the incorrect behavior isn't really a Django bug (if anything it's a Windows problem), but I don't see a feasible way to make the upstream behavior better either- Python is using the platform-defined mechanism and we're just stuck with it being wrong in some cases.

Given there's evidence that problems like this are not vanishingly rare (based on votes on the Stack Overflow discussion and Go bug linked from the ticket) and it doesn't seem feasible to handle the problem upstream, I think Django sits at a position where some kind of workaround is appropriate.

The simplest way might just be a note in the documentation saying "MIME types on Windows might be wrong, here's how you can fix them," though I feel a better solution might be to specifically call mimetypes.init() on startup with an empty list in order to ignore the system-provided mappings (possibly with a user opt-in for system-provided mappings).

Thoughts on working around Windows problems with the dev server like this?

Carlton Gibson

unread,
Sep 25, 2020, 11:09:51 AM9/25/20
to Django developers (Contributions to Django itself)
Hi Peter.

There's a note already for this exact issue in the staticfiles docs.

It mentions Red-Hat and Debian, but it would be reasonable to add a pointer for Windows users too.

Beyond that I'm really not sure what we could do. There's no error we could catch, and we can't/won't reimplement mimetypes… 

Kind Regards,

Carlton

Jacob Rief

unread,
Sep 25, 2020, 11:51:12 AM9/25/20
to Django developers (Contributions to Django itself)
Hi Peter,
as a co-maintainer of django-filer I experienced similar problems. Often you can not rely on the MIME-type provided by the uploading browser.

In your situation, one possible solution would be to guess the MIME-type by looking at the magic header of the received file.
For this purpose you can use the filetype-library.

– Jacob

Reply all
Reply to author
Forward
0 new messages