Fix #100
Former-commit-id: 1130e6e7ae67fdcb866c5dc4eee11de28fc69a96 [formerly 55dc3c0c9bf3b07608f8cade510e2d0d94782ab3] [formerly d5a48b8bef9ae5cc613558b15e98d584a5ed6fa5 [formerly cacca2e6f2
]]
Former-commit-id: cd6f80f2a273d1fa5ed5d35924e416bed7c64194 [formerly d9b42a6d8f025a26107ba91ece5cc4855a2cb681]
Former-commit-id: 2f28d37577a16078e1c191192dfba7ae2b9f2acd
pull/726/head
parent
bae6f640f9
commit
728776dc03
14
file.go
14
file.go
|
@ -209,14 +209,22 @@ func (i *file) RetrieveFileType(checkContent bool) error {
|
|||
mimetype := mime.TypeByExtension(i.Extension)
|
||||
|
||||
if mimetype == "" && checkContent {
|
||||
content, err = ioutil.ReadFile(i.Path)
|
||||
file, err := os.Open(i.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Only the first 512 bytes are used to sniff the content type.
|
||||
buffer := make([]byte, 512)
|
||||
_, err = file.Read(buffer)
|
||||
if err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
// Tries to get the file mimetype using its first
|
||||
// 512 bytes.
|
||||
mimetype = http.DetectContentType(content)
|
||||
mimetype = http.DetectContentType(buffer)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(mimetype, "video") {
|
||||
|
@ -249,7 +257,7 @@ func (i *file) RetrieveFileType(checkContent bool) error {
|
|||
for _, extension := range textExtensions {
|
||||
if strings.HasSuffix(i.Name, extension) {
|
||||
i.Type = "text"
|
||||
return nil
|
||||
goto End
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue