aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go/operation/upload_content.go7
-rw-r--r--go/replication/store_replicate.go2
-rw-r--r--go/weed/upload.go5
3 files changed, 10 insertions, 4 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go
index b73ed0a66..c452ef1dc 100644
--- a/go/operation/upload_content.go
+++ b/go/operation/upload_content.go
@@ -23,12 +23,15 @@ type UploadResult struct {
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
-func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool) (*UploadResult, error) {
+func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool, mtype string) (*UploadResult, error) {
body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf)
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, fileNameEscaper.Replace(filename)))
- h.Set("Content-Type", mime.TypeByExtension(strings.ToLower(filepath.Ext(filename))))
+ if mtype == "" {
+ mtype = mime.TypeByExtension(strings.ToLower(filepath.Ext(filename)))
+ }
+ h.Set("Content-Type", mtype)
if isGzipped {
h.Set("Content-Encoding", "gzip")
}
diff --git a/go/replication/store_replicate.go b/go/replication/store_replicate.go
index 358f7dade..bdc13ee3b 100644
--- a/go/replication/store_replicate.go
+++ b/go/replication/store_replicate.go
@@ -25,7 +25,7 @@ func ReplicatedWrite(masterNode string, s *storage.Store, volumeId storage.Volum
if needToReplicate { //send to other replica locations
if r.FormValue("type") != "replicate" {
if !distributedOperation(masterNode, s, volumeId, func(location operation.Location) bool {
- _, err := operation.Upload("http://"+location.Url+r.URL.Path+"?type=replicate&ts="+strconv.FormatUint(needle.LastModified,10), string(needle.Name), bytes.NewReader(needle.Data), needle.IsGzipped())
+ _, err := operation.Upload("http://"+location.Url+r.URL.Path+"?type=replicate&ts="+strconv.FormatUint(needle.LastModified,10), string(needle.Name), bytes.NewReader(needle.Data), needle.IsGzipped(), string(needle.Mime))
return err == nil
}) {
ret = 0
diff --git a/go/weed/upload.go b/go/weed/upload.go
index 0745f62c5..67bb9adea 100644
--- a/go/weed/upload.go
+++ b/go/weed/upload.go
@@ -6,11 +6,13 @@ import (
"encoding/json"
"errors"
"fmt"
+ "mime"
"net/url"
"os"
"path"
"path/filepath"
"strconv"
+ "strings"
)
var (
@@ -95,7 +97,8 @@ func upload(filename string, server string, fid string) (int, error) {
if isGzipped {
filename = filename[0 : len(filename)-3]
}
- ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), filename, fh, isGzipped)
+ mtype := mime.TypeByExtension(strings.ToLower(filepath.Ext(filename)))
+ ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), filename, fh, isGzipped, mtype)
if e != nil {
return 0, e
}