MCPcopy Create free account
hub / github.com/dearcode/candy / FileUpload

Method FileUpload

client/candy.go:298–316  ·  view source on GitHub ↗

FileUpload 文件上传

(data []byte)

Source from the content-addressed store, hash-verified

296
297// FileUpload 文件上传
298func (c *CandyClient) FileUpload(data []byte) (string, error) {
299 md5 := string(util.MD5(data))
300 exist, err := c.FileExist(md5)
301 if err != nil {
302 return md5, err
303 }
304 //已有别人上传过了
305 if exist {
306 return md5, nil
307 }
308
309 req := &meta.GateUploadFileRequest{File: data}
310 resp, err := c.api.UploadFile(context.Background(), req)
311 if err != nil {
312 return md5, err
313 }
314
315 return md5, resp.Header.Error()
316}
317
318// FileDownload 文件下载
319func (c *CandyClient) FileDownload(key string) ([]byte, error) {

Callers 1

Calls 3

FileExistMethod · 0.95
UploadFileMethod · 0.65
ErrorMethod · 0.45

Tested by 1