mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-20 03:59:56 +08:00
detect mime type before replicating to other volume servers
This commit is contained in:
@@ -93,6 +93,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
|
|||||||
if !isInputGzipped {
|
if !isInputGzipped {
|
||||||
if mtype == "" {
|
if mtype == "" {
|
||||||
mtype = http.DetectContentType(data)
|
mtype = http.DetectContentType(data)
|
||||||
|
// println("detect1 mimetype to", mtype)
|
||||||
if mtype == "application/octet-stream" {
|
if mtype == "application/octet-stream" {
|
||||||
mtype = ""
|
mtype = ""
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,7 @@ func (fs *FilerServer) encrypt(ctx context.Context, w http.ResponseWriter, r *ht
|
|||||||
}
|
}
|
||||||
if pu.MimeType == "" {
|
if pu.MimeType == "" {
|
||||||
pu.MimeType = http.DetectContentType(uncompressedData)
|
pu.MimeType = http.DetectContentType(uncompressedData)
|
||||||
|
// println("detect2 mimetype to", pu.MimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadResult, uploadError := operation.UploadData(urlLocation, pu.FileName, true, uncompressedData, false, pu.MimeType, pu.PairMap, auth)
|
uploadResult, uploadError := operation.UploadData(urlLocation, pu.FileName, true, uncompressedData, false, pu.MimeType, pu.PairMap, auth)
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -50,18 +51,33 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) {
|
|||||||
|
|
||||||
pu.OriginalDataSize = len(pu.Data)
|
pu.OriginalDataSize = len(pu.Data)
|
||||||
pu.UncompressedData = pu.Data
|
pu.UncompressedData = pu.Data
|
||||||
|
// println("received data", len(pu.Data), "isGzipped", pu.IsGzipped, "mime", pu.MimeType, "name", pu.FileName)
|
||||||
|
if pu.MimeType == "" {
|
||||||
|
pu.MimeType = http.DetectContentType(pu.Data)
|
||||||
|
// println("detected mimetype to", pu.MimeType)
|
||||||
|
if pu.MimeType == "application/octet-stream" {
|
||||||
|
pu.MimeType = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
if pu.IsGzipped {
|
if pu.IsGzipped {
|
||||||
if unzipped, e := util.UnGzipData(pu.Data); e == nil {
|
if unzipped, e := util.UnGzipData(pu.Data); e == nil {
|
||||||
pu.OriginalDataSize = len(unzipped)
|
pu.OriginalDataSize = len(unzipped)
|
||||||
pu.UncompressedData = unzipped
|
pu.UncompressedData = unzipped
|
||||||
|
// println("ungzipped data size", len(unzipped))
|
||||||
}
|
}
|
||||||
} else if shouldGzip, _ := util.IsGzippableFileType("", pu.MimeType); pu.MimeType == "" || shouldGzip {
|
} else {
|
||||||
|
ext := filepath.Base(pu.FileName)
|
||||||
|
if shouldGzip, iAmSure := util.IsGzippableFileType(ext, pu.MimeType); pu.MimeType == "" && !iAmSure || shouldGzip && iAmSure {
|
||||||
|
// println("ext", ext, "iAmSure", iAmSure, "shouldGzip", shouldGzip, "mimeType", pu.MimeType)
|
||||||
if compressedData, err := util.GzipData(pu.Data); err == nil {
|
if compressedData, err := util.GzipData(pu.Data); err == nil {
|
||||||
|
if len(compressedData)*10 < len(pu.Data)*9 {
|
||||||
pu.Data = compressedData
|
pu.Data = compressedData
|
||||||
pu.IsGzipped = true
|
pu.IsGzipped = true
|
||||||
}
|
}
|
||||||
|
// println("gzipped data size", len(compressedData))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user