返回的weedPath文件路径中携带请求url中?后的参数
| | |
| | | "mime/multipart" |
| | | "net/http" |
| | | "github.com/kirinlabs/HttpRequest" |
| | | "strings" |
| | | "time" |
| | | ) |
| | | |
| | |
| | | return "", err |
| | | } |
| | | filePath := m["fileUrl"].(string) |
| | | return filePath,nil |
| | | |
| | | return appendCollection2Uri(uri, filePath),nil |
| | | } |
| | | } |
| | | |
| | | // 获得一个fid |
| | | func appendCollection2Uri(weedfsUri, fileUri string) string { |
| | | //判断weedfsUri中是否包含collection参数 |
| | | idx := strings.Index(weedfsUri, "?") |
| | | if idx > -1 { |
| | | return fileUri + weedfsUri[idx:] |
| | | } else { |
| | | return fileUri |
| | | } |
| | | } |
| | | |
| | | // 获得一个fid 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 { |
| | |
| | | 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和fid") |
| | | } |
| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "io/ioutil" |
| | | "testing" |
| | | ) |
| | | |
| | |
| | | } |
| | | |
| | | func TestUpDateFile(t *testing.T) { //1 方法必须传入testing.T 2 方法名必须是以Test开头,驼峰命名 |
| | | 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) |
| | | } |