forked from ohookins/contentful-go
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupload.go
More file actions
31 lines (26 loc) · 745 Bytes
/
upload.go
File metadata and controls
31 lines (26 loc) · 745 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
29
30
31
package contentful
import (
"context"
"fmt"
"io"
"net/http"
)
// UploadService service
type UploadService service
type Upload struct {
Sys Sys `json:"sys"`
}
// Uploads creates a new upload and returns a reference ID
func (service *UploadService) Uploads(ctx context.Context, spaceID string, file io.Reader) (*Upload, error) {
path := fmt.Sprintf("/spaces/%s%s/uploads", spaceID, getEnvPath(service.c))
method := http.MethodPost
req, err := service.c.newRequest(ctx, method, path, nil, file, map[string]string{"Content-Type": "application/octet-stream"})
if err != nil {
return nil, err
}
var uploadResponse *Upload
if err := service.c.do(req, &uploadResponse); err != nil {
return nil, err
}
return uploadResponse, nil
}