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 | 18 +++++++++++++++---
WeedFSClient_test.go | 10 +++-------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/WeedFSClient.go b/WeedFSClient.go
index 4a4e4d1..ce5d0f4 100644
--- a/WeedFSClient.go
+++ b/WeedFSClient.go
@@ -9,6 +9,7 @@
"mime/multipart"
"net/http"
"github.com/kirinlabs/HttpRequest"
+ "strings"
"time"
)
@@ -65,12 +66,22 @@
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 {
@@ -85,7 +96,8 @@
u,ok1 := m["url"]
f,ok2 := m["fid"]
if ok1 && ok2 {
- return "http://"+u.(string)+"/"+f.(string),err
+ filePath := "http://"+u.(string)+"/"+f.(string)
+ return appendCollection2Uri(url, filePath),err
} else {
return "", errors.New("鏈幏鍙栧埌url鍜宖id")
}
diff --git a/WeedFSClient_test.go b/WeedFSClient_test.go
index e1567e6..5aa8be6 100644
--- a/WeedFSClient_test.go
+++ b/WeedFSClient_test.go
@@ -2,7 +2,6 @@
import (
"fmt"
- "io/ioutil"
"testing"
)
@@ -16,11 +15,8 @@
}
func TestUpDateFile(t *testing.T) { //1 鏂规硶蹇呴』浼犲叆testing.T 2 鏂规硶鍚嶅繀椤绘槸浠est寮�澶达紝椹煎嘲鍛藉悕
+ weedfsUri := "http://192.168.5.23:6333/submit?collection=11111-persistent"
url := "http://192.168.5.23:6120/78,22eae6b7875b67"
- data,err := ioutil.ReadFile("./105.jpg")
- path,err := UpDateFile(url,"",data)
- if err != nil {
- t.Error("娴嬭瘯澶辫触")
- }
- fmt.Println(path)
+ filePath := appendCollection2Uri(weedfsUri, url)
+ fmt.Println(filePath)
}
\ No newline at end of file
--
Gitblit v1.8.0