Question

I'm using jclouds 1.6.1-incubating in a web application (using scala playframework 2.1.3, but that shouldn't matter).

Since all other methods in jclouds to receive a blob seem to be deprecated, I want to use

BlobStore.getBlob(container,name).getPayload().getInput()

to get an input stream of the stored data. I want to stream this data then to the browser without actually having to store the whole blob on the server.

Sometimes I only want to get some metadata like

BlobStore.getBlob(container,name).getMetadata().getContentMetadata().getContentLength()

However, the call to

BlobStore.getBlob(container,name)

takes very long to return (I assume, it loads the blob into memory). This causes the webapp to be unresponsive after the user clicks "download". I'd like the cloud data to start streaming immediately to the browser (playframework supports that).

When I want only to get the metadata, this timeout is even worse (I might want to get the metadata for many files without downloading all of them to the webapp).

Am I right? Is BlobStore.getBlob(container,name) actually downloading the file before returning? Is there another way to get an asynchronous input stream I can directly send to the browser?

Was it helpful?

Solution

You can query only metadata with:

BlobMetadata metadata = BlobStore.blobMetadata(container, name);
Long contentLength = metadata.getContentMetadata().getContentLength();

BlobStore.getBlob initiates a download but does not download the entire blob data. Instead it streams data via the Payload or InputStream. It does block until the blobstore returns blob metadata.

Note that you should call Payload.close to ensure that you close the underlying socket.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top