Skip to content

Instantly share code, notes, and snippets.

@nkalra0123
Created January 11, 2020 16:24
Show Gist options
  • Save nkalra0123/bc91615d27598f77006501df217560ef to your computer and use it in GitHub Desktop.
Save nkalra0123/bc91615d27598f77006501df217560ef to your computer and use it in GitHub Desktop.
Upload a file to google cloud storage
// 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