/
requests.go
38 lines (33 loc) · 1.25 KB
/
requests.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
33
34
35
36
37
38
package imagedata
import (
"io"
"github.com/gophercloud/gophercloud"
)
// Upload uploads an image file.
func Upload(client *gophercloud.ServiceClient, id string, data io.Reader) (r UploadResult) {
resp, err := client.Put(uploadURL(client, id), data, nil, &gophercloud.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"},
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Stage performs PUT call on the existing image object in the Imageservice with
// the provided file.
// Existing image object must be in the "queued" status.
func Stage(client *gophercloud.ServiceClient, id string, data io.Reader) (r StageResult) {
resp, err := client.Put(stageURL(client, id), data, nil, &gophercloud.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"},
OkCodes: []int{204},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Download retrieves an image.
func Download(client *gophercloud.ServiceClient, id string) (r DownloadResult) {
resp, err := client.Get(downloadURL(client, id), nil, &gophercloud.RequestOpts{
KeepResponseBody: true,
})
r.Body, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}