snippets_js
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
await googleStorageClient.createBucket(bucketName);
Create a Notification
Create a notification
await googleStorageClient.bucket(bucketName).createNotification(notificationTopic);
Delete a Bucket
Delete a bucket
await googleStorageClient.bucket(bucketName).delete();
Delete a notification
Delete a notification
await googleStorageClient.bucket(bucketName).notification(notificationId).delete();
List Buckets
List buckets
const [buckets] = await googleStorageClient.getBuckets();
buckets.forEach(bucket => {
console.log(bucket.name);
});
List Notifications
List notifications
const [notifications] = await googleStorageClient.bucket(bucketName).getNotifications();
notifications.forEach(notification => {
console.log(notification.id);
});
Upload a File
Upload a file
await googleStorageClient.bucket(bucketName).upload(filePath, {
destination: destinationFileName,
});
Download a File
Download a file
const options = {
destination: destinationFileName,
};
await googleStorageClient.bucket(bucketName).file(fileName).download(options);
Delete a File
Delete a file
await storage.bucket(bucketName).file(fileName).delete();