-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblobs.go
32 lines (25 loc) · 897 Bytes
/
blobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package clccam
import (
"path"
"github.com/pkg/errors"
)
// BlobResponse is returned when uploading a file via POST.
type BlobResponse struct {
// Url from which the uploaded file can be retrieved, e.g. "/services/blobs/download/5c1abf95939a600ea38a8661/test.sh"
Url URI `json:"url"`
// Length of the file in bytes
Length int64 `json:"length"`
// MIME type of the file
ContentType string `json:"content_type"`
// Date/time of the upload
UploadDate Timestamp `json:"upload_date"`
}
// UploadFile uploads the contents of file @name contained in @b.
func (c *Client) UploadFile(name string, b []byte) (res BlobResponse, err error) {
if name == "" {
return res, errors.Errorf("invalid/empty filename")
} else if b == nil || len(b) == 0 {
return res, errors.Errorf("invalid/empty file")
}
return res, c.getResponse("/services/blobs/upload/"+path.Base(name), "POST", b, &res)
}