Skip to main content

Google Storage

Google Storage allows to store any amount of data in Google Cloud Buckets and access it whenever is needed

Google Store snippets available in YepCode editor#

note

The title is the triggering text for YepCode to autocomplete the script

Integration#

New integration from credential
const googleStorageClient = yepcode.integration.googleStorage(credentialSlug);
New integration from plain authentication data
const { Storage } = require("@google-cloud/storage");
const googleStorageCredentials = {  projectId: "YepCode",  credentials: {    type: "service_account",    project_id: "yepcode",    private_key_id: "XXXXX",    private_key: \`-----BEGIN PRIVATE KEY-----\nx\n-----END PRIVATE KEY-----\`,    client_email: "yepcode@example.org",    client_id: "1234567890",    auth_uri: "https://example.org",    token_uri: "https://example.org",    auth_provider_x509_cert_url: "https://example.org",    client_x509_cert_url: "https://example.org",  }};
const googleStorage = new Storage(googleStorageCredentials);

Create a new bucket#

Create a new bucket
async function createBucket() {  await googleStorageClient.createBucket(bucketName);}
createBucket().catch(console.error);

Create a notification#

Create a notification
async function createNotification() {  await googleStorageClient.bucket(bucketName).createNotification(notificationTopic);}
createNotification().catch(console.error);

Delete a bucket#

Delete a bucket
async function deleteBucket() {  await googleStorageClient.bucket(bucketName).delete();}
deleteBucket().catch(console.error);

Delete a notification#

Delete a notification
async function deleteNotification() {  await googleStorageClient.bucket(bucketName).notification(notificationId).delete();}
deleteNotification().catch(console.error);

List buckets#

List buckets
async function listBuckets() {  const [buckets] = await googleStorageClient.getBuckets();
  buckets.forEach(bucket => {    console.log(bucket.name);  });}
listBuckets().catch(console.error);

List notifications#

List notifications
async function listNotifications() {  const [notifications] = await googleStorageClient.bucket(bucketName).getNotifications();
  notifications.forEach(notification => {    console.log(notification.id);  });}
listNotifications().catch(console.error);

Upload a file#

Upload a file
async function uploadFile() {  await googleStorageClient.bucket(bucketName).upload(filePath, {    destination: destinationFileName,  });}
uploadFile().catch(console.error);

Download a file#

Download a file
async function downloadFile() {  const options = {    destination: {1:destinationFileName},  };  await googleStorageClient.bucket(bucketName).file(fileName).download(options);}
downloadFile().catch(console.error);

Delete a file#

Delete a file
async function deleteFile() {  await storage.bucket(bucketName).file(fileName).delete();}
deleteFile().catch(console.error);