Google Storage
Google Storage allows to store any amount of data in Google Cloud Buckets and access it whenever is needed
Official Websitehttps://cloud.google.com/storage
TagsFilesSaas
- JavaScript
- Python
NodeJS package https://www.npmjs.com/package/@google-cloud/storage
Version6.12.0
Source Codehttps://github.com/googleapis/nodejs-storage
Pypi packagehttps://pypi.org/project/google-cloud-storage/
Version2.14.0
Source Codehttps://github.com/googleapis/python-storage
Credential configuration
The projectId
corresponds to the project ID from the Google Developer's Console.
The credentials
field of the JSON corresponds to a JSON key of the service account. This key
is downloaded as a JSON file when you create it. It should be something like this:
{
"type": "service_account",
"project_id": "PROJECT_ID",
"private_key_id": "KEY_ID",
"private_key": "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n",
"client_email": "SERVICE_ACCOUNT_EMAIL",
"client_id": "CLIENT_ID",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL"
}
If you don't have one, create a service account and then, a JSON key for that service account.
info
Ensure to grant permissions over the buckets to manage to this service account.
Here is an example of a filled credential configuration form in YepCode:
Google Store Snippets available in editor
note
The title is the triggering text for YepCode to autocomplete the script.
- JavaScript
- Python
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();
Integration
New integration from credential
storage_client = yepcode.integration.google_storage("credential-slug")
New integration from plain authentication data
from google.cloud.storage.client import Client
from google.oauth2.service_account import Credentials
project_id = "yepcode"
credentialsDict = {
"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",
}
credentials = Credentials.from_service_account_info(credentialsDict)
storage_client = Client(project=project_id, credentials=credentials)
Create a New Bucket
Create a new bucket
storage_client.create_bucket("bucket_name")
Create a Notification
Create a notification
bucket = storage_client.bucket("bucket_name")
notification = bucket.notification(topic_name="topic_name")
notification.create()
print(f"Successfully created notification with ID {notification.notification_id} for bucket {bucket_name}")
Delete a Bucket
Delete a bucket
bucket = storage_client.get_bucket("bucket_name")
bucket.delete()
Delete a Notification
Delete a notification
bucket = storage_client.bucket("bucket_name")
notification = bucket.notification(notification_id=notification_id)
notification.delete()
List Buckets
List buckets
for bucket in storage_client.list_buckets():
print(bucket.name)
List Notifications
List notifications
bucket = storage_client.bucket("bucket_name")
for notification in bucket.list_notifications():
print(notification.notification_id)
Upload a File
Upload a file
bucket = storage_client.bucket("bucket_name")
blob = bucket.blob("destination_file_name")
source_file = BytesIO(b"Some data") # Use a BytesIO object as the "file" to upload
blob.upload_from_file(source_file)
Download a File
Download a file
import io
bucket = storage_client.bucket("bucket_name")
blob = bucket.blob("file_name")
byte_stream = io.BytesIO()
blob.download_to_file(byte_stream)
byte_stream.seek(0)
print(byte_stream.read())