diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-07-11 19:14:55 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-07-11 19:14:55 -0700 |
| commit | 1ac71a111f4d7fd43ffddc14f19056f3091e032d (patch) | |
| tree | bf6e8f9fae18974f54e87acf098347d62243115e /go/operation | |
| parent | 3afc2d2ce6f82d131a2887be44166ac373c57f4f (diff) | |
| download | seaweedfs-1ac71a111f4d7fd43ffddc14f19056f3091e032d.tar.xz seaweedfs-1ac71a111f4d7fd43ffddc14f19056f3091e032d.zip | |
Issue 28: [HELP NEEDED] weed upload does not send correct mime type to
weedfs
Fix is provided by claudiu.raveica
Diffstat (limited to 'go/operation')
| -rw-r--r-- | go/operation/upload_content.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go index cae657b2c..3b7fcf008 100644 --- a/go/operation/upload_content.go +++ b/go/operation/upload_content.go @@ -4,12 +4,15 @@ import ( "bytes" "encoding/json" "errors" - _ "fmt" + "fmt" "io" "io/ioutil" "log" + "mime" "mime/multipart" "net/http" + "net/textproto" + "path/filepath" ) type UploadResult struct { @@ -20,7 +23,10 @@ type UploadResult struct { func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) { body_buf := bytes.NewBufferString("") body_writer := multipart.NewWriter(body_buf) - file_writer, err := body_writer.CreateFormFile("file", filename) + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, filename)) + h.Set("Content-Type", mime.TypeByExtension(filepath.Ext(filename))) + file_writer, err := body_writer.CreatePart(h) if err != nil { log.Println("error creating form file", err) return nil, err |
