github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/imagedata/requests.go (about) 1 package imagedata 2 3 import ( 4 "io" 5 "net/http" 6 7 "github.com/huaweicloud/golangsdk" 8 ) 9 10 // Upload uploads an image file. 11 func Upload(client *golangsdk.ServiceClient, id string, data io.Reader) (r UploadResult) { 12 _, r.Err = client.Put(uploadURL(client, id), data, nil, &golangsdk.RequestOpts{ 13 MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"}, 14 OkCodes: []int{204}, 15 }) 16 return 17 } 18 19 // Stage performs PUT call on the existing image object in the Imageservice with 20 // the provided file. 21 // Existing image object must be in the "queued" status. 22 func Stage(client *golangsdk.ServiceClient, id string, data io.Reader) (r StageResult) { 23 _, r.Err = client.Put(stageURL(client, id), data, nil, &golangsdk.RequestOpts{ 24 MoreHeaders: map[string]string{"Content-Type": "application/octet-stream"}, 25 OkCodes: []int{204}, 26 }) 27 return 28 } 29 30 // Download retrieves an image. 31 func Download(client *golangsdk.ServiceClient, id string) (r DownloadResult) { 32 var resp *http.Response 33 resp, r.Err = client.Get(downloadURL(client, id), nil, &golangsdk.RequestOpts{ 34 KeepResponseBody: true, 35 }) 36 if resp != nil { 37 r.Body = resp.Body 38 r.Header = resp.Header 39 } 40 return 41 }