Search in sources :

Example 36 with BlobId

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;
}
Also used : Acl(com.google.cloud.storage.Acl) BlobId(com.google.cloud.storage.BlobId)

Example 37 with BlobId

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;
}
Also used : Blob(com.google.cloud.storage.Blob) CopyRequest(com.google.cloud.storage.Storage.CopyRequest) BlobId(com.google.cloud.storage.BlobId)

Example 38 with BlobId

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;
}
Also used : Blob(com.google.cloud.storage.Blob) BlobInfo(com.google.cloud.storage.BlobInfo) BlobId(com.google.cloud.storage.BlobId)

Example 39 with BlobId

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()));
}
Also used : HashMap(java.util.HashMap) Builder(com.google.cloud.storage.BlobInfo.Builder) BlobEntryGcsImpl(com.pratilipi.data.type.gcs.BlobEntryGcsImpl) BlobId(com.google.cloud.storage.BlobId)

Aggregations

BlobId (com.google.cloud.storage.BlobId)39 Blob (com.google.cloud.storage.Blob)23 BlobInfo (com.google.cloud.storage.BlobInfo)20 Test (org.junit.Test)12 Acl (com.google.cloud.storage.Acl)9 Storage (com.google.cloud.storage.Storage)9 StorageException (com.google.cloud.storage.StorageException)9 CopyWriter (com.google.cloud.storage.CopyWriter)5 ReadChannel (com.google.cloud.ReadChannel)2 User (com.google.cloud.storage.Acl.User)2 StorageBatch (com.google.cloud.storage.StorageBatch)2 StorageBatchResult (com.google.cloud.storage.StorageBatchResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 BatchResult (com.google.cloud.BatchResult)1 WriteChannel (com.google.cloud.WriteChannel)1 Builder (com.google.cloud.storage.BlobInfo.Builder)1 ComposeRequest (com.google.cloud.storage.Storage.ComposeRequest)1