Integration

Google Cloud Storage Functions: Manage Your GCS Buckets From Xano

Summary

Welcome to Xano's guide on building and managing cloud storage using Google Cloud Storage functions! In this article, we'll walk you through step-by-step instructions to leverage these powerful features within the Xano platform. Let's dive in!

Setting Up Google Cloud Storage Integration

Before we can start utilizing the Google Cloud Storage functions, we need to set up a Google service account with the appropriate permissions. Here's how:

  1. Go to your Google Cloud Console and navigate to the IAM & Admin section.
  2. Create a new Google service account (e.g., "Xano Example").
  3. Assign the following roles to the service account:
  • Storage Object Admin
  • Service Account User
  • Storage Admin
  1. After creating the service account, go to Actions > Manage Keys and add a new JSON key. Download the JSON file.
  2. In Xano, create an environment variable named `service_account_key` and paste the contents of the downloaded JSON file as the value.

With the service account set up, we're ready to start using the Google Cloud Storage functions within Xano.

Working with Google Cloud Storage Functions

Xano provides five handy functions to interact with Google Cloud Storage buckets:

  1. Upload File
  2. Delete File
  3. List Directory
  4. Generate Signed URL
  5. Create Variable from File Resource

Let's explore each of these functions in detail.

Uploading a File

To upload a file to your Google Cloud Storage bucket, follow these steps:

  1. In Xano, add a new function and select Google Cloud Storage > Upload File.
  2. Map the following inputs:
  • Service Account: The environment variable `service_account_key` you created earlier.
  • Bucket Name: The name of your Google Cloud Storage bucket.
  • File Path: The desired path within the bucket where the file should be uploaded (e.g., `/test/new_file.jpg`).
  • File Resource*: The file you want to upload (accessible from the *Storage tab).
  1. Save and run the function.

After running the function, the specified file will be uploaded to the provided file path within your Google Cloud Storage bucket.

Deleting a File

To delete a file from your Google Cloud Storage bucket, follow these steps:

  1. In Xano, add a new function and select Google Cloud Storage > Delete File.
  2. Map the following inputs:
  • Service Account: The environment variable `service_account_key`.
  • Bucket Name: The name of your Google Cloud Storage bucket.
  • File Path: The path of the file you want to delete (e.g., `/test/old_file.pdf`).
  1. Save and run the function.

The specified file will be deleted from your Google Cloud Storage bucket.

Listing Directory Contents

To list the contents of a directory within your Google Cloud Storage bucket, follow these steps:

  1. In Xano, add a new function and select Google Cloud Storage > List Directory.
  2. Map the following inputs:
  • Service Account: The environment variable `service_account_key`.
  • Bucket Name: The name of your Google Cloud Storage bucket.
  • Path: The path of the directory you want to list (e.g., `/images/` or `/` for the root directory).
  1. Save and run the function.

The function will return metadata about the contents of the specified directory, including file names, sizes, and other relevant information.

Generating a Signed URL

If you need to share a file securely with an expiration time, you can generate a signed URL using the following steps:

  1. In Xano, add a new function and select Google Cloud Storage > Generate Signed URL.
  2. Map the following inputs:
  • Service Account: The environment variable `service_account_key`.
  • Bucket Name: The name of your Google Cloud Storage bucket.
  • File Path: The path of the file you want to generate a signed URL for (e.g., `/images/profile.jpg`).
  • Method: The HTTP method for accessing the file (`GET` or `POST`).
  • TTL (Time to Live): The duration (in seconds) for which the signed URL will be valid.
  1. Save and run the function.

The function will return a signed URL that can be shared with others. The URL will expire after the specified TTL (Time to Live) duration.

Creating a Variable from File Resource

If you need to work with a file resource from your Google Cloud Storage bucket within your Xano function stack, you can create a variable from the file using the following steps:

  1. In Xano, add a new function and select Google Cloud Storage > Create Variable from File Resource.
  2. Map the following inputs:
  • Service Account: The environment variable `service_account_key`.
  • Bucket Name: The name of your Google Cloud Storage bucket.
  • File Path: The path of the file you want to create a variable from (e.g., `/images/profile.jpg`).
  1. Save and run the function.

The function will return a variable containing the file resource data, which you can then use within your Xano function stack. This is useful if you need to send the file to another service, store it in a database, or perform any other operations with the file data.

By following these step-by-step guides, you can easily leverage the power of Google Cloud Storage within the Xano platform, enabling you to build and manage cloud storage solutions for your web and mobile applications without writing code.

Happy building!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free