我正在使用http.FileServer来服务一系列mp3文件的目录,然后在JavaScript中用
src
将它们呈现。但是响应却使用Content-Type
text/html
,而不是audio/mpeg
。我该如何设置FileServer响应的MIME类型?我看到了这个问题"在golang HTTP FileServer中设置Content-Type头中的charset属性",但我仍然不确定如何覆盖MIME类型。
我的代码如下:
```go //Go code here ```fs := http.FileServer(http.Dir(dir))
http.Handle("/media", http.StripPrefix("/media", fs))
http.HandleFunc("/", p.playlistHandler)
http.ListenAndServe(":5177", nil)
我遇到的错误是:
HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:5177/media/sample1.mp3 failed.