use of com.google.cloud.storage.BlobId in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method getBlobAcl.
/**
* Example of getting the ACL entry for an entity on a blob.
*/
// [TARGET getAcl(BlobId, Entity)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
// [VARIABLE 42]
public Acl getBlobAcl(String bucketName, String blobName, long blobGeneration) {
// [START getBlobAcl]
BlobId blobId = BlobId.of(bucketName, blobName, blobGeneration);
Acl acl = storage.getAcl(blobId, User.ofAllAuthenticatedUsers());
// [END getBlobAcl]
return acl;
}
use of com.google.cloud.storage.BlobId 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.BlobId 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;
}
use of com.google.cloud.storage.BlobId in project pratilipi by Pratilipi.
the class BlobAccessorGcsImpl2 method createOrUpdateBlob.
@Override
public BlobEntry createOrUpdateBlob(BlobEntry blobEntry) {
BlobId blobId = BlobId.of(bucketName, blobEntry.getName());
Builder blobInfoBuilder = BlobInfo.newBuilder(blobId);
if (blobEntry.getMimeType() != null)
blobInfoBuilder.setContentType(blobEntry.getMimeType());
if (blobEntry.getCacheControl() != null)
blobInfoBuilder.setCacheControl(blobEntry.getCacheControl());
if (blobEntry.getMetaName() != null) {
Map<String, String> metadata = new HashMap<>();
metadata.put(BlobEntry.META_NAME, blobEntry.getMetaName());
blobInfoBuilder.setMetadata(metadata);
}
return new BlobEntryGcsImpl(gcsService.create(blobInfoBuilder.build(), blobEntry.getData()));
}
Aggregations