3.11. 删除 File
Github: github.com/bigfile/bigfile
API
有时候您可能需要删除一个目录或者一个文件,这个 API
的功能正是如此。当你删除一个目录时,务必小心,将会删除某个目录下的所有文件和目录。API
参数如下:
DELETE /api/bigfile/file/delete
name | type | required | description |
---|---|---|---|
token | string | yes | token,要删除的文件必须存在该 Token 的作用域下 |
nonce | string | yes | 32 到 48 长度的随机字符串 |
fileUid | string | yes | file uid |
force | string | no | 默认: false ,强制删除非空目录 |
sign | string | no | 参数签名,如果 Token 是有密钥的,那么它是必填的 |
示例
让我们来删除前面上传的图片:
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),
"fileUid": "64c8a8ecd911630acf1dc26e8319f2dd",
}
body := http.GetParamsSignBody(params, tokenSecret)
api := "https://127.0.0.1:10985/api/bigfile/file/delete?" + body
if request, err = libHttp.NewRequest(libHttp.MethodDelete, 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":10030,
"success":true,
"errors":null,
"data":{
"deletedAt":1567992964,
"ext":"jpeg",
"fileUid":"64c8a8ecd911630acf1dc26e8319f2dd",
"hash":"9536467bde347627e27634a77963105a045f624e290b0f2bbc342834abdd4593",
"hidden":0,
"isDir":0,
"path":"/images/png/profile/profile.jpeg",
"size":4698744
}
}
deletedAt
表示着文件被删除的时间。您可以调用 /api/bigfile/directory/list
来查看当前目录的文件。不出意外,你将会得到下面的结果:
{
"requestId":10031,
"success":true,
"errors":null,
"data":{
"items":[
],
"pages":0,
"total":0
}
}
英文文档:bigfile.site
推荐文章: