Browse Source

Readded DetectContentType

pull/1540/head
Gaspare Iengo 5 years ago
parent
commit
dab7577e34
  1. 4
      test/s3/multipart/aws_upload.go
  2. 12
      weed/command/filer_copy.go
  3. 4
      weed/filesys/filehandle.go
  4. 3
      weed/operation/upload_content.go
  5. 3
      weed/server/filer_server_handlers_write_cipher.go
  6. 3
      weed/storage/needle/needle_parse_upload.go

4
test/s3/multipart/aws_upload.go

@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
"net/http"
"os" "os"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -48,8 +49,7 @@ func main() {
fileInfo, _ := file.Stat() fileInfo, _ := file.Stat()
size := fileInfo.Size() size := fileInfo.Size()
buffer := make([]byte, size) buffer := make([]byte, size)
// fileType := http.DetectContentType(buffer)
fileType := "application/octet-stream"
fileType := http.DetectContentType(buffer)
file.Read(buffer) file.Read(buffer)
path := "/media/" + file.Name() path := "/media/" + file.Name()

12
weed/command/filer_copy.go

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -277,8 +278,7 @@ func (worker *FileCopyWorker) uploadFileAsOne(task FileCopyTask, f *os.File) err
// upload the file content // upload the file content
fileName := filepath.Base(f.Name()) fileName := filepath.Base(f.Name())
// mimeType := detectMimeType(f)
mimeType := "application/octet-stream"
mimeType := detectMimeType(f)
data, err := ioutil.ReadAll(f) data, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
return err 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 { func (worker *FileCopyWorker) uploadFileInChunks(task FileCopyTask, f *os.File, chunkCount int, chunkSize int64) error {
fileName := filepath.Base(f.Name()) fileName := filepath.Base(f.Name())
// mimeType := detectMimeType(f)
mimeType := "application/octet-stream"
mimeType := detectMimeType(f)
chunksChan := make(chan *filer_pb.FileChunk, chunkCount) 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 { func detectMimeType(f *os.File) string {
head := make([]byte, 512) head := make([]byte, 512)
f.Seek(0, io.SeekStart) f.Seek(0, io.SeekStart)
_, err := f.Read(head)
n, err := f.Read(head)
if err == io.EOF { if err == io.EOF {
return "" return ""
} }
@ -497,8 +496,7 @@ func detectMimeType(f *os.File) string {
return "" return ""
} }
f.Seek(0, io.SeekStart) f.Seek(0, io.SeekStart)
// mimeType := http.DetectContentType(head[:n])
mimeType := "application/octet-stream"
mimeType := http.DetectContentType(head[:n])
if mimeType == "application/octet-stream" { if mimeType == "application/octet-stream" {
return "" return ""
} }

4
weed/filesys/filehandle.go

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"net/http"
"os" "os"
"sync" "sync"
"time" "time"
@ -153,8 +154,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
// fh.contentType = http.DetectContentType(data)
fh.contentType = "application/octet-stream"
fh.contentType = http.DetectContentType(data)
fh.f.dirtyMetadata = true fh.f.dirtyMetadata = true
} }

3
weed/operation/upload_content.go

@ -102,8 +102,7 @@ func doUploadData(uploadUrl string, filename string, cipher bool, data []byte, i
shouldGzipNow := false shouldGzipNow := false
if !isInputCompressed { if !isInputCompressed {
if mtype == "" { if mtype == "" {
// mtype = http.DetectContentType(data)
mtype = "application/octet-stream"
mtype = http.DetectContentType(data)
// println("detect1 mimetype to", mtype) // println("detect1 mimetype to", mtype)
if mtype == "application/octet-stream" { if mtype == "application/octet-stream" {
mtype = "" mtype = ""

3
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 uncompressedData = pu.UncompressedData
} }
if pu.MimeType == "" { if pu.MimeType == "" {
// pu.MimeType = http.DetectContentType(uncompressedData)
pu.MimeType = "application/octet-stream"
pu.MimeType = http.DetectContentType(uncompressedData)
// println("detect2 mimetype to", pu.MimeType) // println("detect2 mimetype to", pu.MimeType)
} }

3
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) ext := filepath.Base(pu.FileName)
mimeType := pu.MimeType mimeType := pu.MimeType
if mimeType == "" { if mimeType == "" {
// mimeType = http.DetectContentType(pu.Data)
mimeType = "application/octet-stream"
mimeType = http.DetectContentType(pu.Data)
} }
// println("detected mimetype to", pu.MimeType) // println("detected mimetype to", pu.MimeType)
if mimeType == "application/octet-stream" { if mimeType == "application/octet-stream" {

Loading…
Cancel
Save