How to upload image from url using Image service REST API

Asked by Ksenia on 2015-10-08

Hello,
I'm looking for a way to upload images from external URL using Image service API , but I can't find in API docs how to pass URL argument to create image method or to any other method.
Is API v2 support uploading images from URL and how?
And the same questions about API v1.

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Glance Edit question
Assignee:
No assignee Edit question
Solved by:
Ksenia
Solved:
2015-10-13
Last query:
2015-10-13
Last reply:
2015-10-12

For v1 you can do:

 glance --os-image-api-version 1 image-create --copy-from ...

for v2 there is currently no universally recognised way to do this.

There is some design work going on around importing images using v2 at the moment, stay tuned.

Ksenia (ks-malysheva) said : #2

Thanks for the answer,
but I need a way to do this via REST Api from my frontend.

I make a POST request to glance endpoint:
POST /v1/images
with request payload:
{
   "name":"webV1",
   "copy_from":"http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/mini.iso",
   "disk_format":"iso",
   "container_format":"bare"
}

Response received:
400 Bad Request
Invalid disk format 'None' for image.

But image is created, with id instead of name, in state queued (and it never changes to Active) and 0 bytes size.
What is correct way to upload image from url via Rest api?

wangxiyuan (wangxiyuan) said : #3

In v1, You should pass parameter in header, like : x-image-meta-disk_format, not in body.

Ksenia (ks-malysheva) said : #4

Hi all,
thanks for answers!

Looks like in REST Api v1 we can do following request:
POST v1/images

headers: {
  'x-glance-api-copy-from': '<image_url>',
  'x-image-meta-name': '<image_name>'
}

Request shouldn't contain body.

Gary Marchiny (gary-marchiny) said : #5

I've recently reported a 'bug' that is related to this topic: https://bugs.launchpad.net/glance/+bug/1513473