Skip to content

Commit 1fbce98

Browse files
committed
glance: image download should use the GET method
In order to properly download an image the http method HEAD has been replaced with GET. Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
1 parent a1ec355 commit 1fbce98

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

glance-client/src/main/java/com/woorea/openstack/glance/ImagesResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Upload(ImageUpload imageUpload) {
147147
public class Download extends OpenStackRequest<ImageDownload> {
148148

149149
public Download(String id) {
150-
super(CLIENT, HttpMethod.HEAD, new StringBuilder("/images/").append(id).toString(), null, ImageDownload.class);
150+
super(CLIENT, HttpMethod.GET, new StringBuilder("/images/").append(id).toString(), null, ImageDownload.class);
151151
header("Accept", "application/octet-stream");
152152
}
153153

openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.woorea.openstack.examples.glance;
22

3+
import com.woorea.openstack.glance.model.ImageDownload;
34
import com.woorea.openstack.glance.model.ImageUpload;
45
import com.woorea.openstack.keystone.utils.KeystoneTokenProvider;
56

@@ -12,6 +13,7 @@
1213
import com.woorea.openstack.keystone.model.Access.Service.Endpoint;
1314

1415
import java.io.ByteArrayInputStream;
16+
import java.io.IOException;
1517

1618
public class GlanceListImages {
1719

@@ -58,6 +60,16 @@ public static void main(String[] args) {
5860
uploadImage.setInputStream(new ByteArrayInputStream(IMAGE_CONTENT.getBytes()));
5961
glance.images().upload(newImage.getId(), uploadImage).execute();
6062

63+
// Downloading the image and displaying the image content
64+
try {
65+
byte[] imgContent = new byte[IMAGE_CONTENT.length()];
66+
ImageDownload downloadImage = glance.images().download(newImage.getId()).execute();
67+
downloadImage.getInputStream().read(imgContent, 0, imgContent.length);
68+
System.out.println(new String(imgContent));
69+
} catch (IOException e) {
70+
e.printStackTrace();
71+
}
72+
6173
Images images = glance.images().list(false).execute();
6274

6375
for (Image image : images) {

0 commit comments

Comments
 (0)