英文:
Golang “net/http” DetectContentType error
问题
使用DetectContentType
函数来检测上传文件的content-type
,但结果始终是application/octet-stream
。这只是该函数的默认返回值。
那么问题是什么?
英文:
Use DetectContentType
to detect the uploaded file content-type
, but the result is always application/octet-stream
.this is just the default return in this function.
So what's the problem?
答案1
得分: 1
标准库的代码只能根据特定的标准算法来检测某些类型(比如包含几个常见标签的HTML),更多信息请参考https://golang.org/src/net/http/sniff.go。你可以使用github.com/rakyll/magicmime,它使用libmagic和cgo来猜测更多的文件类型。
英文:
The standard library's code is only supposed to detect certain types (like HTML that contains one of a few common tags) according to a certain standardized algorithm--more in https://golang.org/src/net/http/sniff.go. You could use github.com/rakyll/magicmime, which uses libmagic and cgo to guess at more file types.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论