Serve static files with correct mime type for download
Author: qount25Created Feb 15, 2025Updated Dec 2, 2025
I'm using `ServeFiles` to let users download .mp4 files, but browsers start playing the files instead of forcing users to download them. Normally, this is solved by setting the correct mime type, but I'm not sure I understand where to do this. I was able to set mime type for one of my endpoints in one of handlers (unrelated to serving static files), but that's because I had access to `http.ResponseWriter`. How do I go about it with static files?
Source: julienschmidt/httprouter