Blob.newBlob() not found

28 views
Skip to first unread message

Loadeed

unread,
Apr 15, 2012, 12:20:54 PM4/15/12
to jclouds
Hello!

I am trying to save Blob on File System but I can't find method
newBlob(blobName) in class BlobStore. I followed quickstart here:
http://www.jclouds.org/documentation/quickstart/filesystem

I did it this way:

BlobBuilder blobBuilder = blobStore.blobBuilder("Test");
Blob blob = blobBuilder.build();
blob.setPayload("test data");
blobStore.putBlob(containerName, blob);

but I don't know if it's right, because it gives me some errors.

Thanks.

Adrian Cole

unread,
Apr 15, 2012, 3:05:21 PM4/15/12
to jcl...@googlegroups.com

Hi, Thomas.

I'd recommend starting with jclouds-examples on github.  You'll blobstore-basics, which you can play around with.  Syntax looks ok.  If you run into errors, pls paste them!

-A

--
You received this message because you are subscribed to the Google Groups "jclouds" group.
To post to this group, send email to jcl...@googlegroups.com.
To unsubscribe from this group, send email to jclouds+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jclouds?hl=en.

Chris Strand

unread,
Apr 15, 2012, 3:09:39 PM4/15/12
to jcl...@googlegroups.com
The filesystem api/provider has a slightly annoying thing in it at the moment to do with credentials, see Issue 735.

I don't really use it much so can't guarantee this is the best way, but here is how I create a filesystem Blobstore to work around the above issue:

BlobStore blobStore;
Properties properties = new Properties();
// Set where to save the blobs
String baseDir = System.getProperty("user.home") + "/localblobstore";
properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, baseDir);
properties.setProperty("jclouds.credential", "");
blobStoreFilesystem = new BlobStoreContextFactory().
  createContext(provider, properties).
    getBlobStore();

Hope that helps,

Chris

Loadeed

unread,
Apr 16, 2012, 4:20:21 PM4/16/12
to jclouds
I was able to save, retreive and delete blob from my file system, but
I don't know how to get data, when I retreive back blob:

Code:

//save blob
Blob blob = blobStore.blobBuilder("test").build();
//data
String data = "test data";
//set payload
blob.setPayload(data);
blobStore.putBlob(containerName, blob);
System.out.println("Blob saved!");

//retreive blob
Blob blobRetrieved = blobStore.getBlob(containerName, "test");
String dataRetreived =
blob.getPayload()... //
how can I get string (test data) that I saved to blob before here
System.out.println("Blob retreived, data: " + dataRetreived

Thanks.

On 15 apr., 21:09, Chris Strand <clastr...@gmail.com> wrote:
> The filesystem api/provider has a slightly annoying thing in it at the
> moment to do with credentials, see Issue
> 735<http://code.google.com/p/jclouds/issues/detail?id=735>
> .
>
> I don't really use it much so can't guarantee this is the best way, but
> here is how I create a filesystem Blobstore to work around the above issue:
>
> BlobStore blobStore;Properties properties = new Properties();// Set
> where to save the blobsString baseDir =
> System.getProperty("user.home") +
> "/localblobstore";properties.setProperty(FilesystemConstants.PROPERTY_BASED IR,
> baseDir);properties.setProperty("jclouds.credential",
> "");blobStoreFilesystem = new BlobStoreContextFactory().
>   createContext(provider, properties).
>     getBlobStore();
>
> Hope that helps,
>
> Chris
>

Adrian Cole

unread,
Apr 16, 2012, 4:46:41 PM4/16/12
to jcl...@googlegroups.com
Hi, there.

Blob.getPayload() has the contents you are looking for.

you can try Strings2.toStringAndClose(Blob.getPayload().getInput()) or
various other inputstream options!

-A

Andrew Phillips

unread,
Apr 16, 2012, 5:10:07 PM4/16/12
to jcl...@googlegroups.com
> how can I get string (test data) that I saved to blob before here
> System.out.println("Blob retreived, data: " + dataRetreived

You're right, the blobstore guide [1] doesn't go into a lot of detail
on this, although there is a small bit at the end.

Have a look at, for example, the FileUploader exercise, especially things like

byte[] payloadRead = ByteStreams.toByteArray(
store.getBlob(containerName, filename).get().getPayload().getInput());

In general, Payload [3, 4] is your friend ;-)

Hope this helps!

ap

[1] http://www.jclouds.org/documentation/userguide/blobstore-guide
[2]
https://github.com/demobox/jclouds-cloud-storage-workshop/blob/master/exercise3/src/main/java/org/jclouds/labs/blobstore/exercise3/FileUploader.java
[3]
https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/io/Payload.java
[4]
http://demobox.github.com/jclouds-maven-site-1.4.0/1.4.0/jclouds-multi/apidocs/index.html?org/jclouds/io/Payload.html

Reply all
Reply to author
Forward
0 new messages