FileUpload 文件上传
(data []byte)
| 296 | |
| 297 | // FileUpload 文件上传 |
| 298 | func (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 文件下载 |
| 319 | func (c *CandyClient) FileDownload(key string) ([]byte, error) { |