Currently Being Moderated
May 30, 2011 9:43 PM
Uploading Media via vcloud-java-sdk. Potential SDK bug?
I cannot seem to upload from an input stream via the vcloud-java-sdk.
I get a root cause exception in
Caused by: com.vmware.vcloud.sdk.VCloudException: No file(s) to upload
at com.vmware.vcloud.sdk.Media.uploadFile(Media.java:219)
I am using code like so...
MediaType mediaType = new MediaType();
mediaType.setName(filename);
mediaType.setDescription(description);
mediaType.setImageType(ImageType.ISO);
mediaType.setSize(size)
Media media = vdc.createMedia(mediaType);
mediaType = media.getResource();
media = Media.getMediaByReference(client, media.getReference());
media.uploadFile(filename, inputStream, size);
...
the XML that the rest interface is returning is puzzling.
<Media xmlns="http://www.vmware.com/vcloud/v1" xmlns:ns2="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ns3="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:ns4="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ns5="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ns6="http://www.vmware.com/vcloud/versions" xmlns:ns7="http://www.vmware.com/vcloud/extension/v1" size="345345345" imageType="iso" name="install48.iso">
<Description>some description</Description>
</Media>
31/05/2011 4:39:53 PM com.vmware.vcloud.sdk.RestUtil post
INFO: POST Request Content-Type: application/vnd.vmware.vcloud.media+xml
31/05/2011 4:39:53 PM com.vmware.vcloud.sdk.RestUtil post
INFO: POST Request charset: null
31/05/2011 4:39:54 PM com.vmware.vcloud.sdk.RestUtil post
INFO: status Code: 201
31/05/2011 4:39:54 PM com.vmware.vcloud.sdk.RestUtil post
INFO: Status Line: HTTP/1.1 201 Created
31/05/2011 4:39:54 PM com.vmware.vcloud.sdk.RestUtil post
INFO: Status: Created
31/05/2011 4:39:54 PM com.vmware.vcloud.sdk.RestUtil post
INFO: Response: <?xml version="1.0" encoding="UTF-8"?>
<Media xmlns="http://www.vmware.com/vcloud/v1" size="345345345" imageType="iso" status="0" name="install48.iso" type="application/vnd.vmware.vcloud.media+xml" href="https://10.0.11.31/api/v1.0/media/51961368" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://10.0.11.31/api/v1.0/schema/master.xsd">
<Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://10.0.11.31/api/v1.0/vdc/215376122"/>
<Link rel="edit" type="application/vnd.vmware.vcloud.media+xml" href="https://10.0.11.31/api/v1.0/media/51961368"/>
<Description>some description</Description>
<Files>
<File size="345345345" bytesTransferred="0" name="file">
<Link rel="upload:default" href="https://10.0.11.31:443/transfer/d2664ecc-3e2f-4113-9692-7c6624e4783d/file"/>
</File>
</Files>
</Media>
the snippet that worries me is the filename in the file element.
<File size="345345345" bytesTransferred="0" name="file">
<Link rel="upload:default" href="https://10.0.11.31:443/transfer/d2664ecc-3e2f-4113-9692-7c6624e4783d/file"/>
</File>
it appears to be ignoring my file name that is in the original request
<Media xmlns="http://www.vmware.com/vcloud/v1" xmlns:ns2="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ns3="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:ns4="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ns5="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ns6="http://www.vmware.com/vcloud/versions" xmlns:ns7="http://www.vmware.com/vcloud/extension/v1" size="345345345" imageType="iso" name="install48.iso">
<Description>some description</Description>
</Media>
i've tried resetting the file in the file list to the correct name but if I fetch the media again from vcloud the response is like so...
INFO: Response: <?xml version="1.0" encoding="UTF-8"?>
<Media xmlns="http://www.vmware.com/vcloud/v1" size="345345345" imageType="iso" status="0" name="install48.iso" type="application/vnd.vmware.vcloud.media+xml" href="https://10.0.11.31/api/v1.0/media/51961368" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://10.0.11.31/api/v1.0/schema/master.xsd">
<Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://10.0.11.31/api/v1.0/vdc/215376122"/>
<Link rel="edit" type="application/vnd.vmware.vcloud.media+xml" href="https://10.0.11.31/api/v1.0/media/51961368"/>
<Description>some description</Description>
<Files>
<File size="345345345" bytesTransferred="0" name="file">
<Link rel="upload:default" href="https://10.0.11.31:443/transfer/d2664ecc-3e2f-4113-9692-7c6624e4783d/file"/>
</File>
</Files>
</Media>
Is something broken?