use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method batchGet.
/**
* Example of getting information on several blobs using a single batch request.
*/
// [TARGET get(BlobId...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name1"]
// [VARIABLE "my_blob_name2"]
public List<Blob> batchGet(String bucketName, String blobName1, String blobName2) {
// [START batchGet]
BlobId firstBlob = BlobId.of(bucketName, blobName1);
BlobId secondBlob = BlobId.of(bucketName, blobName2);
List<Blob> blobs = storage.get(firstBlob, secondBlob);
// [END batchGet]
return blobs;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method updateBlobWithMetageneration.
/**
* Example of udating a blob, only if the blob's metageneration matches a value, otherwise a
* {@link StorageException} is thrown.
*/
// [TARGET update(BlobInfo, BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob updateBlobWithMetageneration(String bucketName, String blobName) {
// [START updateBlobWithMetageneration]
Blob blob = storage.get(bucketName, blobName);
BlobInfo updatedInfo = blob.toBuilder().setContentType("text/plain").build();
storage.update(updatedInfo, BlobTargetOption.metagenerationMatch());
// [END updateBlobWithMetageneration]
return blob;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method updateBlob.
/**
* Example of replacing blob's metadata.
*/
// [TARGET update(BlobInfo)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob updateBlob(String bucketName, String blobName) {
// [START updateBlob]
Map<String, String> newMetadata = new HashMap<>();
newMetadata.put("key", "value");
storage.update(BlobInfo.newBuilder(bucketName, blobName).setMetadata(null).build());
Blob blob = storage.update(BlobInfo.newBuilder(bucketName, blobName).setMetadata(newMetadata).build());
// [END updateBlob]
return blob;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method rotateBlobEncryptionKey.
/**
* Example of rotating the encryption key of a blob.
*/
// [TARGET copy(CopyRequest)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE "old_encryption_key"]
// [VARIABLE "new_encryption_key"]
public Blob rotateBlobEncryptionKey(String bucketName, String blobName, String oldEncryptionKey, String newEncryptionKey) {
// [START storageRotateEncryptionKey]
BlobId blobId = BlobId.of(bucketName, blobName);
CopyRequest request = CopyRequest.newBuilder().setSource(blobId).setSourceOptions(BlobSourceOption.decryptionKey(oldEncryptionKey)).setTarget(blobId, BlobTargetOption.encryptionKey(newEncryptionKey)).build();
Blob blob = storage.copy(request).getResult();
// [END storageRotateEncryptionKey]
return blob;
}
use of com.google.cloud.storage.Blob in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method createBlob.
/**
* Example of creating a blob with no content.
*/
// [TARGET create(BlobInfo, BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob createBlob(String bucketName, String blobName) {
// [START createBlob]
BlobId blobId = BlobId.of(bucketName, blobName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo);
// [END createBlob]
return blob;
}
Aggregations