SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
escaping upload file name special characters if already gzipped, avoid gzipping again
Chris Lu5e3b6e968a93
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.goindex e606ef7e39..b73ed0a663 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")diff --git a/go/weed/upload.go b/go/weed/upload.goindex 8e75b387bd..7256093cf4 100644--- a/go/weed/upload.go+++ b/go/weed/upload.go@@ -78,7 +78,12 @@ func upload(filename string, server string, fid string) (int, error) {debug("Failed to stat file:", filename)return 0, fiErr}- ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), path.Base(filename), fh, false)+ filename = path.Base(filename)+ isGzipped := path.Ext(filename) == ".gz"+ if isGzipped {+ filename = filename[0:len(filename)-3]+ }+ ret, e := operation.Upload("http://"+server+"/"+fid+"?ts="+strconv.Itoa(int(fi.ModTime().Unix())), filename, fh, isGzipped)if e != nil {return 0, e}diff --git a/go/weed/volume.go b/go/weed/volume.goindex dbc0ee5471..a22babd45d 100644--- a/go/weed/volume.go+++ b/go/weed/volume.go@@ -272,13 +272,13 @@ func parseURLPath(path string) (vid, fid, filename, ext string) {vid, fid, filename = parts[1], parts[2], parts[3]ext = filepath.Ext(filename)case 2:- parts := strings.Split(path, "/")- vid, fid = parts[1], parts[2]- dotIndex := strings.LastIndex(fid, ".")- if dotIndex > 0 {- ext = fid[dotIndex:]- fid = fid[0:dotIndex]- }+ parts := strings.Split(path, "/")+ vid, fid = parts[1], parts[2]+ dotIndex := strings.LastIndex(fid, ".")+ if dotIndex > 0 {+ ext = fid[dotIndex:]+ fid = fid[0:dotIndex]+ }default:sepIndex := strings.LastIndex(path, "/")commaIndex := strings.LastIndex(path[sepIndex:], ",")