From 34e03e7cf6f98edcd3315da77016050d54f177b2 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 15 May 2014 01:56:08 -0700 Subject: [PATCH] iphone usually has upper cased .JPG extension refactor --- go/storage/needle.go | 7 ++++++- go/weed/weed_server/volume_server_handlers.go | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/go/storage/needle.go b/go/storage/needle.go index 353ca6dd5..b29a88159 100644 --- a/go/storage/needle.go +++ b/go/storage/needle.go @@ -2,6 +2,7 @@ package storage import ( "code.google.com/p/weed-fs/go/glog" + "code.google.com/p/weed-fs/go/images" "code.google.com/p/weed-fs/go/util" "encoding/hex" "errors" @@ -93,7 +94,7 @@ func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string modifiedTime, _ = strconv.ParseUint(r.FormValue("ts"), 10, 64) return } -func NewNeedle(r *http.Request) (n *Needle, e error) { +func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) { fname, mimeType, isGzipped := "", "", false n = new(Needle) fname, n.Data, mimeType, isGzipped, n.LastModified, e = ParseUpload(r) @@ -116,6 +117,10 @@ func NewNeedle(r *http.Request) (n *Needle, e error) { } n.SetHasLastModifiedDate() + if fixJpgOrientation && strings.HasSuffix(strings.ToLower(string(n.Name)), ".jpg") { + n.Data = images.FixJpgOrientation(n.Data) + } + n.Checksum = NewCRC(n.Data) commaSep := strings.LastIndex(r.URL.Path, ",") diff --git a/go/weed/weed_server/volume_server_handlers.go b/go/weed/weed_server/volume_server_handlers.go index 65a3d14f8..8c9c78137 100644 --- a/go/weed/weed_server/volume_server_handlers.go +++ b/go/weed/weed_server/volume_server_handlers.go @@ -150,16 +150,12 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) { writeJsonError(w, r, ve) return } - needle, ne := storage.NewNeedle(r) + needle, ne := storage.NewNeedle(r, vs.FixJpgOrientation) if ne != nil { writeJsonError(w, r, ne) return } - if vs.FixJpgOrientation && strings.HasSuffix(string(needle.Name), ".jpg") { - needle.Data = images.FixJpgOrientation(needle.Data) - } - ret := operation.UploadResult{} size, errorStatus := topology.ReplicatedWrite(vs.masterNode, vs.store, volumeId, needle, r) if errorStatus == "" {