3.8. 更新 File

未匹配的标注

Github: github.com/bigfile/bigfile

API

文件上传之后,我们可能会选择将文件移动至另一个路径,或者重命名,或者隐藏它。我们来看一下这个 API 的参数列表:

PATCH /api/bigfile/file/update

名称 类型 必填 描述
token string yes token,要更新的文件必须存在该 Token 的作用域下
fileUid string yes 文件唯一 ID
nonce string yes 32 到 48 长度的随机字符串
path string no 文件存储路径,相对于 Token 的路径
sign string no 参数签名,如果 Token 是有密钥的,那么它是必填的
hidden bool no 将文件置为隐藏,被隐藏的文件无法被下载

示例

package main

import (
    "fmt"
    "io/ioutil"
    libHttp "net/http"
    "strings"

    "github.com/bigfile/bigfile/databases/models"
    "github.com/bigfile/bigfile/http"
)

func main() {
    token := "49f92acd696260abba1bc4062d157199"
    tokenSecret := "9bcac735fd7f25947a3909998420affa"
    body := http.GetParamsSignBody(map[string]interface{}{
        "token":   token,
        "fileUid": "64c8a8ecd911630acf1dc26e8319f2dd",
        "nonce":   models.RandomWithMd5(128),
        "path":    "/profile/profile.jpeg",
    }, tokenSecret)
    request, err := libHttp.NewRequest(
        libHttp.MethodPatch, "https://127.0.0.1:10985/api/bigfile/file/update", strings.NewReader(body))
    if err != nil {
        fmt.Println(err)
        return
    }
    request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    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":10021,
    "success":true,
    "errors":null,
    "data":{
        "ext":"jpeg",
        "fileUid":"64c8a8ecd911630acf1dc26e8319f2dd",
        "hash":"9536467bde347627e27634a77963105a045f624e290b0f2bbc342834abdd4593",
        "hidden":0,
        "isDir":0,
        "path":"/images/png/profile/profile.jpeg",
        "size":4698744
    }
}

英文文档:bigfile.site

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
Michael001
讨论数量: 0
发起讨论 只看当前版本


暂无话题~