Golang中的”net/http”包的DetectContentType函数错误。

huangapple go评论79阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2016年11月15日 11:53:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/40601725.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定