相关疑难解决方法(0)

http.FileServer 响应错误的 MIME “Content-Type”

我正在使用 http.FileServer 来提供 mp3 文件的目录,然后我的模板src在 javascript 中。但是,响应使用Content-Type text/html代替audio/mpeg。如何设置 FileServer 响应的 mime 类型,我看到了这个问题Setting the 'charset' property on the Content-Type header in the golang HTTP FileServer,但我仍然不确定如何覆盖 mime 类型。

我的代码如下所示:

fs := http.FileServer(http.Dir(dir))
http.Handle("/media", http.StripPrefix("/media", fs))
http.HandleFunc("/", p.playlistHandler)
http.ListenAndServe(":5177", nil)
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:5177/media/sample1.mp3 failed.
Run Code Online (Sandbox Code Playgroud)

javascript mime content-type fileserver go

6
推荐指数
1
解决办法
3386
查看次数

标签 统计

content-type ×1

fileserver ×1

go ×1

javascript ×1

mime ×1