mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
better detect file mime type
This commit is contained in:
parent
3f1d79512f
commit
9cacaf5eca
|
@ -4,12 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"mime"
|
"net/http"
|
||||||
"path"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer2"
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
@ -130,12 +127,7 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f
|
||||||
|
|
||||||
if req.Offset == 0 {
|
if req.Offset == 0 {
|
||||||
// detect mime type
|
// detect mime type
|
||||||
detectedMIME := mimetype.Detect(data)
|
fh.contentType = http.DetectContentType(data)
|
||||||
fh.contentType = detectedMIME.String()
|
|
||||||
if ext := path.Ext(fh.f.Name); ext != detectedMIME.Extension() {
|
|
||||||
fh.contentType = mime.TypeByExtension(ext)
|
|
||||||
}
|
|
||||||
|
|
||||||
fh.dirtyMetadata = true
|
fh.dirtyMetadata = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,12 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
|
||||||
contentIsGzipped := isInputGzipped
|
contentIsGzipped := isInputGzipped
|
||||||
shouldGzipNow := false
|
shouldGzipNow := false
|
||||||
if !isInputGzipped {
|
if !isInputGzipped {
|
||||||
|
if mtype == "" {
|
||||||
|
mtype = http.DetectContentType(data)
|
||||||
|
if mtype == "application/octet-stream" {
|
||||||
|
mtype = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {
|
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {
|
||||||
shouldGzipNow = true
|
shouldGzipNow = true
|
||||||
} else if !iAmSure && mtype == "" && len(data) > 128 {
|
} else if !iAmSure && mtype == "" && len(data) > 128 {
|
||||||
|
|
Loading…
Reference in a new issue