Home > Article > Backend Development > How to Correct the \'text/html\' MIME Type Error When Serving Files with http.FileServer?
Correcting MIME Type with http.FileServer
When using http.FileServer to serve static files, it's essential to ensure the correct MIME type is set. By default, the FileServer responds with "text/html," which can lead to errors when serving non-HTML files.
Problem: Users encountering the error "HTTP 'Content-Type' of 'text/html' is not supported..." when trying to access MP3 files through http.FileServer.
Answer:
The problem stems from an improper pattern in the FileServer's URI, which results in the handler not being called for MP3 requests. To resolve this:
By making these changes, you ensure that the FileServer handles requests for MP3 files correctly, and the appropriate MIME type ("audio/mpeg") is set in the response, resolving the issue.
The above is the detailed content of How to Correct the \'text/html\' MIME Type Error When Serving Files with http.FileServer?. For more information, please follow other related articles on the PHP Chinese website!