Cloud Storage

Cloud Storage Functions allow you to interact with Cloud Storage providers such as Google Cloud Storage directly in the function stack.

Leveraging a Cloud Storage solution requires you to have an account with the external provider and gives you enhanced control over your file storage.

Google Cloud Storage

Manage Google Cloud Storage buckets directly in the Xano function stack.

Google Service Account

You need to set up a Google Service Account in the Google Cloud Console.

Navigate to IAM & Admin and select Service Accounts.

Select + Create Service Account.

Roles

Be sure to include the following Roles for the Service Account:

  • Service Account User

  • Storage Admin

  • Storage Object Admin

Once the Service Account is created, select actions and Manage keys.

Then add a new key and select the JSON option.

Google will provide a JSON file for download. Open the file and copy the JSON key. Paste this into your Xano workspace either as an Environment Variable or as a variable in the function stack that you are using the Google Cloud Storage functions.

The JSON key must be entered as a text string. Do not import the key as JSON when adding it to Xano.

List Directory

List the contents of a Google Cloud Storage Bucket.

Service Account - the JSON key, stored as text, from your Google Service Account

Bucket - the name of the Bucket you wish to access.

Path - the path you wish to see the contents of.

Signed URL

Generate a signed URL to provide limited permissions. These can be used with a TTL (time to live) similar to an expiring token.

Service Account - the JSON key, stored as text, from your Google Service Account

Bucket - the name of the Bucket you wish to access.

filePath - the path of the file you wish to generate the URL for.

Method - the HTTP method (GET or POST)

TTL - time to live, in seconds. (How long until the URL expires).

Upload a File

Upload a File to the specific Google Cloud Storage bucket.

Service Account - the JSON key, stored as text, from your Google Service Account

Bucket - the name of the Bucket you upload a file to.

filePath - the path and name of the file you wish to store in the bucket. For example "files/image1" will upload the image in the files folder and name it image1.

File - the file being uploaded. This should come from a file resource input or a file resource variable.

Delete File

Delete a specific file from a Bucket.

Service Account - the JSON key, stored as text, from your Google Service Account

Bucket - the name of the Bucket that contains the file.

filePath - the path of the file you wish to delete from the Bucket.

Create Variable From File Resource

Return the file resource as a variable in Xano, including the raw image. This can be used, for example, to send to another service if file transfer is needed.

Service Account - the JSON key, stored as text, from your Google Service Account

Bucket - the name of the Bucket that contains the file.

filePath - the path of the file you wish to create a variable of.

Example - Using the Variable Created from File Resource

Turn your API endpoint into a redirect to the file by returning the data field from the return variable and setting a custom header of Content-Type with the mime of the file resource.

Here's an example return of Create Variable from File Resource:

If we return the raw image (data) and use a Set Header function to define Content-Type the mime (in this example image/png). We can have our endpoint URL redirect to the file.

Amazon S3

Access Key and Secret Access Key

From your AWS Developer Console, navigate to Security Credentials.

Scroll down to Access Keys and select Create access key unless you have an access key and secret already generated.

Select Command Line Interface (CLI) as the use case and choose next, optionally add a description, then create the access key.

Store the Access key and Secret access key in a safe place. It's recommended to save these in your Xano workspace as Environment Variables as they will be used in the Amazon S3 Cloud Storage Functions.

Bucket and Region

The s3 bucket name and region will also be required when calling the Amazon s3 Cloud Storage Functions.

When navigating to your s3 buckets, the bucket name can be found under name. The region is under region but only requires the identifier. For example, in the below image the bucket name is xano-s3-test and the region is us-west-2.

Amazon S3: List Directory

Lists the directory details of the specific Amazon s3 bucket.

Bucket - The name of the s3 bucket you want to get the details of.

Region - The region of the bucket.

Key - The access key

Secret - The secret access key

Next_page_token - optional. The next page token is provided in the response if there is a next page, use this value to get the next page of items. S3 buckets limit 1,000 items per page.

Amazon S3: Signed URL

Creates a signed URL of the file to be shared with an expiration.

Bucket - The name of the s3 bucket you want to get the details of.

Region - The region of the bucket.

Key - The access key

Secret - The secret access key

File_key - The file key of the file. This can be found in the s3 bucket when selecting the file and finding Key. Additionally, the Key is listed in the payload for List Directory.

TTL - Time to live. How long, in seconds, the signed URL is viewable until it expires.

Amazon S3: Upload a File

Upload a file to a specified Amazon S3 Bucket

Bucket - The name of the s3 bucket you want to get the details of.

Region - The region of the bucket.

Key - The access key

Secret - The secret access key

File_key - Optionally define the file key. If nothing is defined, one will be automatically assigned by Amazon S3.

File - The file being uploaded. This must come from a file resource input or file resource variable.

Amazon S3: Delete File

Delete a file from a specified S3 Bucket.

Bucket - The name of the s3 bucket you want to get the details of.

Region - The region of the bucket.

Key - The access key

Secret - The secret access key

File_key - The file key of the file you wish to delete.

Amazon S3: Create Var From File Resource

Return the file resource as a variable in Xano, including the raw image. This can be used, for example, to send to another service if file transfer is needed.

Bucket - The name of the s3 bucket you want to get the details of.

Region - The region of the bucket.

Key - The access key

Secret - The secret access key

File_key - The file key of the file you wish to return the file resource as a variable.

The result, shown on the right-hand side of the above image returns an object with the file name, size, mime type, and raw image represented in the path data.

Check out the example above to return the image through an API request.

Last updated