Created
January 11, 2020 16:24
-
-
Save nkalra0123/bc91615d27598f77006501df217560ef to your computer and use it in GitHub Desktop.
Upload a file to google cloud storage
This file contains 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
// Bucket ID is our Project ID | |
String bucket = "gs://" + projectIdProvider.getProjectId(); | |
// Generate a random file name | |
filename = UUID.randomUUID().toString() + ".jpg"; | |
WritableResource resource = (WritableResource) | |
context.getResource(bucket + "/" + filename); | |
// Write the file to Cloud Storage using WritableResource | |
try (OutputStream os = resource.getOutputStream()) { | |
os.write(file.getBytes()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment