diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-07-15 17:26:00 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-07-15 17:26:00 -0700 |
| commit | 5e3b6e968a930a735fcb208bfeda372fe9ba7efc (patch) | |
| tree | 643b3e6eb5175da86c8009d5c254cb06c1fab03b /go/operation/upload_content.go | |
| parent | dd66193bfbc36bb43bace01e2f88fe52f983c838 (diff) | |
| download | seaweedfs-5e3b6e968a930a735fcb208bfeda372fe9ba7efc.tar.xz seaweedfs-5e3b6e968a930a735fcb208bfeda372fe9ba7efc.zip | |
escaping upload file name special characters
if already gzipped, avoid gzipping again
Diffstat (limited to 'go/operation/upload_content.go')
| -rw-r--r-- | go/operation/upload_content.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.go index e606ef7e3..b73ed0a66 100644 --- a/go/operation/upload_content.go +++ b/go/operation/upload_content.go @@ -21,11 +21,13 @@ type UploadResult struct { Error string } +var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"") + func Upload(uploadUrl string, filename string, reader io.Reader, isGzipped bool) (*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"`, filename)) + 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 isGzipped { h.Set("Content-Encoding", "gzip") |
