filer store original data size instead of data size after gzip

This commit is contained in:
Chris Lu 2018-12-22 13:11:07 -08:00
parent 141d302492
commit be946c9e54
4 changed files with 15 additions and 13 deletions

View file

@ -91,7 +91,7 @@ func submitForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl st
} }
debug("parsing upload file...") debug("parsing upload file...")
fname, data, mimeType, pairMap, isGzipped, lastModified, _, _, pe := storage.ParseUpload(r) fname, data, mimeType, pairMap, isGzipped, originalDataSize, lastModified, _, _, pe := storage.ParseUpload(r)
if pe != nil { if pe != nil {
writeJsonError(w, r, http.StatusBadRequest, pe) writeJsonError(w, r, http.StatusBadRequest, pe)
return return
@ -134,7 +134,7 @@ func submitForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl st
m["fileName"] = fname m["fileName"] = fname
m["fid"] = assignResult.Fid m["fid"] = assignResult.Fid
m["fileUrl"] = assignResult.PublicUrl + "/" + assignResult.Fid m["fileUrl"] = assignResult.PublicUrl + "/" + assignResult.Fid
m["size"] = uploadResult.Size m["size"] = originalDataSize
m["eTag"] = uploadResult.ETag m["eTag"] = uploadResult.ETag
writeJsonQuiet(w, r, http.StatusCreated, m) writeJsonQuiet(w, r, http.StatusCreated, m)
return return

View file

@ -27,7 +27,7 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {
writeJsonError(w, r, http.StatusBadRequest, ve) writeJsonError(w, r, http.StatusBadRequest, ve)
return return
} }
needle, ne := storage.NewNeedle(r, vs.FixJpgOrientation) needle, originalSize, ne := storage.CreateNeedleFromRequest(r, vs.FixJpgOrientation)
if ne != nil { if ne != nil {
writeJsonError(w, r, http.StatusBadRequest, ne) writeJsonError(w, r, http.StatusBadRequest, ne)
return return
@ -44,7 +44,7 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {
if needle.HasName() { if needle.HasName() {
ret.Name = string(needle.Name) ret.Name = string(needle.Name)
} }
ret.Size = needle.DataSize ret.Size = uint32(originalSize)
setEtag(w, needle.Etag()) setEtag(w, needle.Etag())
writeJsonQuiet(w, r, httpStatus, ret) writeJsonQuiet(w, r, httpStatus, ret)
} }

View file

@ -50,7 +50,7 @@ func (n *Needle) String() (str string) {
} }
func ParseUpload(r *http.Request) ( func ParseUpload(r *http.Request) (
fileName string, data []byte, mimeType string, pairMap map[string]string, isGzipped bool, fileName string, data []byte, mimeType string, pairMap map[string]string, isGzipped bool, originalDataSize int,
modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) { modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) {
pairMap = make(map[string]string) pairMap = make(map[string]string)
for k, v := range r.Header { for k, v := range r.Header {
@ -60,7 +60,7 @@ func ParseUpload(r *http.Request) (
} }
if r.Method == "POST" { if r.Method == "POST" {
fileName, data, mimeType, isGzipped, isChunkedFile, e = parseMultipart(r) fileName, data, mimeType, isGzipped, originalDataSize, isChunkedFile, e = parseMultipart(r)
} else { } else {
isGzipped = false isGzipped = false
mimeType = r.Header.Get("Content-Type") mimeType = r.Header.Get("Content-Type")
@ -76,11 +76,11 @@ func ParseUpload(r *http.Request) (
return return
} }
func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) { func CreateNeedleFromRequest(r *http.Request, fixJpgOrientation bool) (n *Needle, originalSize int, e error) {
var pairMap map[string]string var pairMap map[string]string
fname, mimeType, isGzipped, isChunkedFile := "", "", false, false fname, mimeType, isGzipped, isChunkedFile := "", "", false, false
n = new(Needle) n = new(Needle)
fname, n.Data, mimeType, pairMap, isGzipped, n.LastModified, n.Ttl, isChunkedFile, e = ParseUpload(r) fname, n.Data, mimeType, pairMap, isGzipped, originalSize, n.LastModified, n.Ttl, isChunkedFile, e = ParseUpload(r)
if e != nil { if e != nil {
return return
} }

View file

@ -12,7 +12,7 @@ import (
) )
func parseMultipart(r *http.Request) ( func parseMultipart(r *http.Request) (
fileName string, data []byte, mimeType string, isGzipped, isChunkedFile bool, e error) { fileName string, data []byte, mimeType string, isGzipped bool, originalDataSize int, 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)
@ -64,6 +64,8 @@ func parseMultipart(r *http.Request) (
} }
} }
originalDataSize = len(data)
isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm")) isChunkedFile, _ = strconv.ParseBool(r.FormValue("cm"))
if !isChunkedFile { if !isChunkedFile {