It’s not perfect without downloading and inspecting the file itself, but I’ve added a “best effort” educated guess at figuring out the mime type from the filename alone which should resolve the common cases:
https://github.com/discourse/discourse/commit/41ffafb65e4fc9a305e35b900d689f15cf0f3890