Created
September 22, 2017 19:26
-
-
Save DazWilkin/b32d00fcf69793c871e886c92816b074 to your computer and use it in GitHub Desktop.
Medium:170922: Cloud Storage w/ Cloud Client Library for Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.google.dazwilkin; | |
import com.google.cloud.storage.Blob; | |
import com.google.cloud.storage.Bucket; | |
import com.google.cloud.storage.Storage; | |
import com.google.cloud.storage.StorageOptions; | |
public class CloudStorage | |
{ | |
private static final String PROJECT_ID = "[[YOUR-PROJECT-ID]]"; | |
private static final String BUCKET_NAME = "[[BUCKET]]"; | |
public static void main(String[] args) { | |
Storage storage = StorageOptions.getDefaultInstance().getService(); | |
for (Bucket bucket : storage.list().iterateAll()) { | |
System.out.println(bucket.getName()); | |
} | |
Bucket bucket = storage.get(BUCKET_NAME); | |
for (Blob blob : bucket.list().iterateAll()) { | |
System.out.println(blob.getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment