From 2d5640d3c8c027da4b2e868df9d9cf6e42554287 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期五, 20 十一月 2020 11:20:39 +0800 Subject: [PATCH] 返回的weedPath文件路径中携带请求url中?后的参数 --- WeedFSClient.go | 25 ++++++++++++++++++++++--- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/WeedFSClient.go b/WeedFSClient.go index f513168..ce5d0f4 100644 --- a/WeedFSClient.go +++ b/WeedFSClient.go @@ -9,6 +9,7 @@ "mime/multipart" "net/http" "github.com/kirinlabs/HttpRequest" + "strings" "time" ) @@ -65,23 +66,41 @@ return "", err } filePath := m["fileUrl"].(string) - return filePath,nil + + return appendCollection2Uri(uri, filePath),nil } } -// 鑾峰緱涓�涓猣id +func appendCollection2Uri(weedfsUri, fileUri string) string { + //鍒ゆ柇weedfsUri涓槸鍚﹀寘鍚玞ollection鍙傛暟 + idx := strings.Index(weedfsUri, "?") + if idx > -1 { + return fileUri + weedfsUri[idx:] + } else { + return fileUri + } +} +// 鑾峰緱涓�涓猣id url eg:http://192.168.5.23:6333/assign/dir?collection=11111-persistent func GetFid(url string)(weedPath string ,err error) { res,err := HttpRequest.NewRequest().Post(url) if err != nil { fmt.Println("缃戠粶浼犺緭閿欒锛�") + return "", err } var m map[string]interface{} err = res.Json(&m) if err != nil { return "",err } - return "http://"+m["url"].(string)+"/"+m["fid"].(string),err + u,ok1 := m["url"] + f,ok2 := m["fid"] + if ok1 && ok2 { + filePath := "http://"+u.(string)+"/"+f.(string) + return appendCollection2Uri(url, filePath),err + } else { + return "", errors.New("鏈幏鍙栧埌url鍜宖id") + } } func UpDateFile(uri string, fileName string, fileData []byte,timeout time.Duration) (m map[string]interface{}, err error) { -- Gitblit v1.8.0