-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfile.go
More file actions
28 lines (23 loc) · 802 Bytes
/
file.go
File metadata and controls
28 lines (23 loc) · 802 Bytes
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
package backlog
import (
"context"
)
// FileUploadResponse : response of uploading file
type FileUploadResponse struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Size *int `json:"size,omitempty"`
}
// UploadFile uploads a file
func (c *Client) UploadFile(fpath string) (*FileUploadResponse, error) {
return c.UploadFileContext(context.Background(), fpath)
}
// UploadFileContext uploads a file and setting a custom context
func (c *Client) UploadFileContext(ctx context.Context, fpath string) (*FileUploadResponse, error) {
u := "/api/v2/space/attachment"
fileUploadResponse := new(FileUploadResponse)
if err := c.UploadMultipartFile(ctx, "POST", u, fpath, "file", &fileUploadResponse); err != nil {
return nil, err
}
return fileUploadResponse, nil
}