Store file action step

The use and options of the Store file step in Actions.

After reading this article, you’ll know the following:

  • Store file step and its functionality

  • How to use this step in your application

What is Store file step?

Store file action step in Betty Blocks allows you to store files using a provided URL or configuration variable. This functionality is particularly useful when you need to save files from external sources directly into your application’s storage.

Store file icon

The step is typically used with an HTTP(s) step that fetches the file from an external source (e.g. API). Upon successful upload, the step returns a reference to the Store file step in the database. This reference can then be used in further steps, such as Create or Update records within your application.

Imagine this case: you are building an application that manages articles for an online magazine. Each article may have an associated image. By using the HTTP(s) step, you can fetch images from an external data API, store them within your application with the Store file step, and then associate them with specific articles with Update record step.

Store file step configuration example

Options

From the Store file, Options tab is open by default. Here you can manage the following options:

  • Model: The model containing the property where the reference to the stored file will be saved

  • Property: The specific property of the chosen model where the file reference will be stored. This property must be designated to handle file references

  • URL: The URL of the externally hosted file to be stored. Only HTTP and HTTPS URLs are supported

Store file step options
  • Headers: Key-value pairs of headers to be included in the request to fetch the file from the URL. Usually, it is an authentication key provided by an API source.

  • As: The name of the variable that will store the reference to the stored file. This variable can be used further in the flow to create or update records with the file reference.

Store file step options (continued)

Variables tab is used to add more variables to the step, which can be used for dynamic value mapping. This is particularly useful when the values that need to be assigned depend on other variables or calculations within your application.

Read more about working with variables here.

Using Store file step

Let’s take a basic use case for this example. Assume you want to retrieve an image from the Pexels API using a photo ID (Number), and store it in the new article record in your application.

  1. Create a new action in your application and add the HTTP(s) step to the action flow and configure it according to Get a photo API info:

    • Choose GET method to retrieve the file(s)

    • Headers will contain the authentication name and value (password)

    • Protocol is defined as HTTPS

    • URL contains the initial storage along with image ID: https://api.pexels.com/v1/photos/2014422

HTTP(s) step configuration
  • Finish the configuration with a schema model as a temporary storage

  • As: Set a variable name for the response data and save it as an object (e.g. pexels_article_image)

HTTP(s) step configuration (continued)

2. Add the Store file step to your action flow and configure it:

  • Model: Here you select a model you want to store the image in and select the property accordingly (Article model with article_image - a file or image type)

  • URL repeats the initial one from the HTTP(s) step

  • Headers: If additional headers are needed for the store request, add them here

  • As: Set a variable name for storing (e.g. uploaded_article_image)

Store file configuration

3. After saving the Store file step, add Create record step:

  1. Select a model to create a new record in (Article)

  2. Add properties:

    1. Article image with uploaded_article_image (from Store file) as a variable

    2. Number with selected_articles.id variable (image ID saved from HTTP(s) step)

  3. Define the name for the result variable and save your configuration

Create record step configuration

This flow will fetch the image from the Pexels API using the specified photo ID, store it within your database, and then create a new article record in the Article model with the image file reference stored in the image (or file) property.

Mind that the Store file action step is not used for uploading images to the front end of your application. For such things, we use the Image upload form component. Find out how it’s done in Creating a document upload feature article.