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"
"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()

12
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 ""
}

4
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
}

3
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 = ""

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
}
if pu.MimeType == "" {
// pu.MimeType = http.DetectContentType(uncompressedData)
pu.MimeType = "application/octet-stream"
pu.MimeType = http.DetectContentType(uncompressedData)
// 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)
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" {

Loading…
Cancel
Save