Browse Source

ensure mime type checking by lower cased file name extension

pull/2/head
Chris Lu 12 years ago
parent
commit
db46565d18
  1. 3
      go/operation/upload_content.go

3
go/operation/upload_content.go

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"net/textproto" "net/textproto"
"path/filepath" "path/filepath"
"strings"
) )
type UploadResult struct { type UploadResult struct {
@ -25,7 +26,7 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
body_writer := multipart.NewWriter(body_buf) body_writer := multipart.NewWriter(body_buf)
h := make(textproto.MIMEHeader) 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"`, filename))
h.Set("Content-Type", mime.TypeByExtension(filepath.Ext(filename)))
h.Set("Content-Type", mime.TypeByExtension(strings.ToLower(filepath.Ext(filename))))
file_writer, err := body_writer.CreatePart(h) file_writer, err := body_writer.CreatePart(h)
if err != nil { if err != nil {
log.Println("error creating form file", err) log.Println("error creating form file", err)

Loading…
Cancel
Save