From c11b2332f9c13d75c4224151e803e40ac3515278 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Mon, 24 Jan 2022 17:04:34 +0300 Subject: [PATCH] [#123] Add url-encoded queries for attributes Signed-off-by: Angira Kekteeva --- README.md | 13 +++++++++++++ downloader/download.go | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01bc002..fd87190 100644 --- a/README.md +++ b/README.md @@ -298,6 +298,9 @@ where `$ATTRIBUTE_NAME` is the name of the attribute we want to use, `$ATTRIBUTE_VALUE` is the value of this attribute that the target object should have. +**NB!** The attribute key and value must be url encoded, i.e., if you want to download an object with the attribute value +`a cat`, the value in the request must be `a+cat`. In the same way with the attribute key. + If multiple objects have specified attribute with specified value, then the first one of them is returned (and you can't get others via this interface). @@ -306,6 +309,11 @@ Example for file name attribute: ``` $ wget http://localhost:8082/get_by_attribute/88GdaZFTcYJn1dqiSECss8kKPmmun6d6BfvC4zhwfLYM/FileName/cat.jpeg ``` +Or when the filename includes special symbols: +``` +$ wget http://localhost:8082/get_by_attribute/88GdaZFTcYJn1dqiSECss8kKPmmun6d6BfvC4zhwfLYM/FileName/cat+jpeg # means 'cat jpeg' +$ wget http://localhost:8082/get_by_attribute/88GdaZFTcYJn1dqiSECss8kKPmmun6d6BfvC4zhwfLYM/FileName/cat%25jpeg # means 'cat%jpeg' +``` Some other user-defined attribute: @@ -313,6 +321,11 @@ Some other user-defined attribute: $ wget http://localhost:8082/get_by_attribute/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ/Ololo/100500 ``` +Or when the attribute includes special symbols: +``` +$ wget http://localhost:8082/get_by_attribute/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ/Olo%2Blo/100500 # means Olo+lo +``` + An optional `download=true` argument for `Content-Disposition` management is also supported (more on that below): diff --git a/downloader/download.go b/downloader/download.go index d669cfb..e71873e 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "net/url" "path" "strconv" "strings" @@ -314,8 +315,8 @@ func (d *Downloader) byAttribute(c *fasthttp.RequestCtx, f func(request, pool.Ob var ( httpStatus = fasthttp.StatusBadRequest scid, _ = c.UserValue("cid").(string) - key, _ = c.UserValue("attr_key").(string) - val, _ = c.UserValue("attr_val").(string) + key, _ = url.QueryUnescape(c.UserValue("attr_key").(string)) + val, _ = url.QueryUnescape(c.UserValue("attr_val").(string)) log = d.log.With(zap.String("cid", scid), zap.String("attr_key", key), zap.String("attr_val", val)) ) containerID := cid.New()