avoid reparsing the multipart form

This commit is contained in:
Chris Lu
2018-07-27 02:10:10 -07:00
parent e4b7e31902
commit 4d322df95e
2 changed files with 10 additions and 9 deletions

View File

@@ -59,10 +59,8 @@ func ParseUpload(r *http.Request) (
} }
} }
isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm"))
if r.Method == "POST" { if r.Method == "POST" {
fileName, data, mimeType, isGzipped, e = parseMultipart(r, isChunkedFile) fileName, data, mimeType, isGzipped, isChunkedFile, e = parseMultipart(r)
} else { } else {
isGzipped = false isGzipped = false
mimeType = r.Header.Get("Content-Type") mimeType = r.Header.Get("Content-Type")

View File

@@ -8,10 +8,11 @@ import (
"net/http" "net/http"
"path" "path"
"strings" "strings"
"strconv"
) )
func parseMultipart(r *http.Request, isChunkedFile bool) ( func parseMultipart(r *http.Request) (
fileName string, data []byte, mimeType string, isGzipped bool, e error) { fileName string, data []byte, mimeType string, isGzipped, isChunkedFile bool, e error) {
form, fe := r.MultipartReader() form, fe := r.MultipartReader()
if fe != nil { if fe != nil {
glog.V(0).Infoln("MultipartReader [ERROR]", fe) glog.V(0).Infoln("MultipartReader [ERROR]", fe)
@@ -63,6 +64,8 @@ func parseMultipart(r *http.Request, isChunkedFile bool) (
} }
} }
isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm"))
if !isChunkedFile { if !isChunkedFile {
dotIndex := strings.LastIndex(fileName, ".") dotIndex := strings.LastIndex(fileName, ".")