Package com.google.cloud.storage


package com.google.cloud.storage
A client for Cloud Storage - Unified object storage.

Here's a simple usage example the Java Storage client. This example shows how to create a Storage object.


 Storage storage = StorageOptions.getDefaultInstance().getService();
 BlobId blobId = BlobId.of("bucket", "blob_name");
 BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
 Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
 

This second example shows how to update an object's content if the object exists.


 Storage storage = StorageOptions.getDefaultInstance().getService();
 BlobId blobId = BlobId.of("bucket", "blob_name");
 Blob blob = storage.get(blobId);
 if (blob != null) {
   byte[] prevContent = blob.getContent();
   System.out.println(new String(prevContent, UTF_8));
   WritableByteChannel channel = blob.writer();
   channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
   channel.close();
 }
 

For more detailed code examples, see the sample library.

When using google-cloud from outside of App/Compute Engine, you have to specify a project ID and provide credentials.

Operations in this library are generally thread safe, except for the use of BlobReadChannel and BlobWriteChannel.

See Also: