diff --git a/test/s3/multipart/aws_upload.go b/test/s3/multipart/aws_upload.go index 24a186625..8c15cf6ed 100644 --- a/test/s3/multipart/aws_upload.go +++ b/test/s3/multipart/aws_upload.go @@ -6,6 +6,7 @@ import ( "bytes" "flag" "fmt" + "net/http" "os" "github.com/aws/aws-sdk-go/aws" @@ -48,8 +49,7 @@ func main() { fileInfo, _ := file.Stat() size := fileInfo.Size() buffer := make([]byte, size) - // fileType := http.DetectContentType(buffer) - fileType := "application/octet-stream" + fileType := http.DetectContentType(buffer) file.Read(buffer) path := "/media/" + file.Name() diff --git a/weed/command/filer_copy.go b/weed/command/filer_copy.go index 03680e81b..88148acc5 100644 --- a/weed/command/filer_copy.go +++ b/weed/command/filer_copy.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "net/url" "os" "path/filepath" @@ -277,8 +278,7 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err // upload the file content fileName := filepath.Base(f.Name()) - // mimeType := detectMimeType(f) - mimeType := "application/octet-stream" + mimeType := detectMimeType(f) data, err := ioutil.ReadAll(f) if err != nil { return err @@ -365,8 +365,7 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err func (worker *FileCopyWorker) uploadFileInChunks(task FileCopyTask, f *os.File, chunkCount int, chunkSize int64) error { fileName := filepath.Base(f.Name()) - // mimeType := detectMimeType(f) - mimeType := "application/octet-stream" + mimeType := detectMimeType(f) chunksChan := make(chan *filer_pb.FileChunk, chunkCount) @@ -488,7 +487,7 @@ func (worker *FileCopyWorker) uploadFileInChunks(task FileCopyTask, f *os.File, func detectMimeType(f *os.File) string { head := make([]byte, 512) f.Seek(0, io.SeekStart) - _, err := f.Read(head) + n, err := f.Read(head) if err == io.EOF { return "" } @@ -497,8 +496,7 @@ func detectMimeType(f *os.File) string { return "" } f.Seek(0, io.SeekStart) - // mimeType := http.DetectContentType(head[:n]) - mimeType := "application/octet-stream" + mimeType := http.DetectContentType(head[:n]) if mimeType == "application/octet-stream" { return "" } diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 61ebbfc09..687588788 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "math" + "net/http" "os" "sync" "time" @@ -153,8 +154,7 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f if req.Offset == 0 { // detect mime type - // fh.contentType = http.DetectContentType(data) - fh.contentType = "application/octet-stream" + fh.contentType = http.DetectContentType(data) fh.f.dirtyMetadata = true } diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go index f783da440..e9002d09d 100644 --- a/weed/operation/upload_content.go +++ b/weed/operation/upload_content.go @@ -102,8 +102,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i shouldGzipNow := false if !isInputCompressed { if mtype == "" { - // mtype = http.DetectContentType(data) - mtype = "application/octet-stream" + mtype = http.DetectContentType(data) // println("detect1 mimetype to", mtype) if mtype == "application/octet-stream" { mtype = "" diff --git a/weed/server/filer_server_handlers_write_cipher.go b/weed/server/filer_server_handlers_write_cipher.go index 175a880bf..60082a8d4 100644 --- a/weed/server/filer_server_handlers_write_cipher.go +++ b/weed/server/filer_server_handlers_write_cipher.go @@ -37,8 +37,7 @@ func (fs *FilerServer) encrypt(ctx context.Context, w http.ResponseWriter, r *ht uncompressedData = pu.UncompressedData } if pu.MimeType == "" { - // pu.MimeType = http.DetectContentType(uncompressedData) - pu.MimeType = "application/octet-stream" + pu.MimeType = http.DetectContentType(uncompressedData) // println("detect2 mimetype to", pu.MimeType) } diff --git a/weed/storage/needle/needle_parse_upload.go b/weed/storage/needle/needle_parse_upload.go index da4dd0ee9..4d244046e 100644 --- a/weed/storage/needle/needle_parse_upload.go +++ b/weed/storage/needle/needle_parse_upload.go @@ -66,8 +66,7 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) { ext := filepath.Base(pu.FileName) mimeType := pu.MimeType if mimeType == "" { - // mimeType = http.DetectContentType(pu.Data) - mimeType = "application/octet-stream" + mimeType = http.DetectContentType(pu.Data) } // println("detected mimetype to", pu.MimeType) if mimeType == "application/octet-stream" {