jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 1 | package imagedata |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "net/http" |
| 6 | |
| 7 | "github.com/gophercloud/gophercloud" |
| 8 | ) |
| 9 | |
| 10 | // Upload uploads image file |
jrperritt | f47ca3a | 2017-02-17 11:23:12 -0600 | [diff] [blame] | 11 | func Upload(client *gophercloud.ServiceClient, id string, data io.Reader) (r UploadResult) { |
jrperritt | c5c590a | 2016-11-04 14:41:15 -0500 | [diff] [blame] | 12 | _, r.Err = client.Put(uploadURL(client, id), data, nil, &gophercloud.RequestOpts{ |
| 13 | MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"}, |
| 14 | OkCodes: []int{204}, |
| 15 | }) |
| 16 | return |
| 17 | } |
| 18 | |
| 19 | // Download retrieves file |
| 20 | func Download(client *gophercloud.ServiceClient, id string) (r DownloadResult) { |
| 21 | var resp *http.Response |
| 22 | resp, r.Err = client.Get(downloadURL(client, id), nil, nil) |
| 23 | if resp != nil { |
| 24 | r.Body = resp.Body |
| 25 | r.Header = resp.Header |
| 26 | } |
| 27 | return |
| 28 | } |