3.10. 浏览目录
Github: github.com/bigfile/bigfile
API
我们经常需要查看某个目录下有哪些文件,在 Bigile
中,我们可以根据下面的 API
查看:
GET /api/bigfile/directory/list
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
token | string | yes | 列出该 Token 下的所有目录 |
nonce | string | yes | 32 到 48 长度的随机字符串 |
sign | string | no | 参数签名,如果 Token 是有密钥的,那么它是必填的 |
subDir | string | no | 默认: / ,列出 Token 根目录 |
sort | string | no | 默认:-type , 例如: type, -type, name, -name, time and -time |
limit | int | no | 默认: 10 , 最小: 10 , 最大: 20 |
offset | int | no | 默认: 0 |
示例
package main
import (
"fmt"
"io/ioutil"
libHttp "net/http"
"strings"
"github.com/bigfile/bigfile/databases/models"
"github.com/bigfile/bigfile/http"
)
func main() {
var (
err error
request *libHttp.Request
token = "49f92acd696260abba1bc4062d157199"
tokenSecret = "9bcac735fd7f25947a3909998420affa"
)
params := map[string]interface{}{
"token": token,
"nonce": models.RandomWithMd5(255),
}
body := http.GetParamsSignBody(params, tokenSecret)
api := "https://127.0.0.1:10985/api/bigfile/directory/list?" + body
if request, err = libHttp.NewRequest(libHttp.MethodGet, api, strings.NewReader("")); err != nil {
fmt.Println(err)
return
}
resp, err := libHttp.DefaultClient.Do(request)
if err != nil {
fmt.Println(err)
return
}
if bodyBytes, err := ioutil.ReadAll(resp.Body); err != nil {
fmt.Println(err)
return
} else {
fmt.Println(string(bodyBytes))
}
}
这个请求将会得到如下的响应:
{
"requestId":10028,
"success":true,
"errors":null,
"data":{
"items":[
{
"fileUid":"034ef654f7e787240cac901c197f09cc",
"hidden":0,
"isDir":1,
"path":"/images/png/profile",
"size":4698744
},
{
"fileUid":"03ccc6c26ec7c3a0fe2be90c3f3882d0",
"hidden":0,
"isDir":1,
"path":"/images/png/profiles",
"size":0
}
],
"pages":1,
"total":2
}
}
但是我们没有看到前面上传的图片,因为它不再 Token
的根目录下,如果您想查看它,您应该设置 subDir=/profile
,如果你试了,你将会得到下面的响应:
{
"requestId":10029,
"success":true,
"errors":null,
"data":{
"items":[
{
"ext":"jpeg",
"fileUid":"64c8a8ecd911630acf1dc26e8319f2dd",
"hash":"9536467bde347627e27634a77963105a045f624e290b0f2bbc342834abdd4593",
"hidden":0,
"isDir":0,
"path":"/images/png/profile/profile.jpeg",
"size":4698744
}
],
"pages":1,
"total":1
}
}
英文文档:bigfile.site
推荐文章: