Thank you for quick response. It helped.
On Tue, Jul 15, 2014 at 5:49 PM, Markus von Rüden <m...@opennms.com> wrote: > On 15.07.2014 14:04, SANDEEP BAZAR wrote: > > I am trying to store and retrieve binary objects from swift using > > org.jclouds.openstack.swift.v1 API. > > > > SwiftApi swiftApi; > > ObjectApi objectApi; > > SwiftObject object; > > swiftApi = ContextBuilder.newBuilder(provider) > > .endpoint("http://X.X.X.X:5000/v2.0/") > > .credentials(identity, credential) > > .modules(modules) > > .buildApi(SwiftApi.class); > > > > objectApi = swiftApi.getObjectApiForRegionAndContainer(REGION, > objectPath); > > object = objectApi.get(objectName); > > System.out.println("object: "+object); > > > > *Output:* > > object: SwiftObject{name=ssl.txt, uri= > > > http://X.X.X.X:8080/v1/AUTH_c9b9a23a5e8e4a45921898a5ac306f29/Personal_Info/ssl.txt > , > > etag=d76cad4bfabde5a5fc16a31a3ce82847, lastModified=Tue Jul 15 15:42:33 > IST > > 2014, metadata={key1=value1, key3=value3, key2=value2}} > > > > When I dump the stream as string I see headers and mime parts arriving > but > > I don't understand how to access the data > > > > Is there any way to get the content of the object and write to the local > > file. > Hey, > > when using blob storage APIs (OpenStack Swift, Amazon S3, etc.) you > usually work on the meta data. > > So your example enables you to use the API itself. > If you want to access the object you need to address the object > (ObjectAPI) and then use the object's payload. > > Have a look at [1] to get started. > > It would be something like this: > > ObjectApi objectApi = > swiftApi.getObjectApiForRegionAndContainer("MyRegion", "MyContainerName"); > SwiftObject object = objectApi.get("file.txt"); // the object name > Payload payload = object.getPayload(); > > With that payload you can then download the object. > Either with java build in mechanisms or using a 3rd party library such > as Google Guava. > > See [2] for Payload details. > > Kind regards > Markus¹ > > > [1] https://jclouds.apache.org/guides/openstack/#swift > [2] > > http://jclouds.apache.org/reference/javadoc/1.7.x/org/jclouds/io/Payload.html >