I developed a method of setting a default image to records where no image is initially uploaded. I’d like to share this method with our community in case anyone might find an application for this functionality.
This example utilizes an image field and a text field on the users table. As a result, if a new user record does not have a profile image, the default will be set and the text field will indicate that the pipe ran on the record. The user can proceed to edit their profile to change the image anytime.
The first step in implementing this method will be to ensure that your data structure is set up. Add the image and text field to your data table. In addition, to ensure that your images are hosted in an accessible location, I recommend creating a separate data table to store any default images you may want to utilize with this method.
As a note, we will not be using this table directly but will be pulling the source url from our images stored in this data table. If your images are already hosted, you will not need to create a new data table.
At this time, you will want to take note of the source url of your image wherever it is hosted. If you stored your default image in a Tadabase data table, a quick way to get the source url is to open up the record to edit, right-click the image, and copy the image address. We’ll use this later in the example when we set up the table rule.
Next, let’s set up the pipe that will save the image to the new record. In this case, we’ll create the pipe call utilizing the update existing record API call (see our API docs here for reference).
If you do not already have a pipe you can add this call to, you will want to create a new pipe, and add a call. To do this, click Add Pipe, navigate to the API Calls tab, and click Add New Call. In this case, we’ll be configuring the call’s overview, parameters, headers, request, and response tabs. We’ll cover each tab in order from left to right.
First, we’ll establish the url for the API call which is going to be the update existing record Tadabase API call. Be srue to also set the type to POST.
Next, add 3 parameters. Be sure that your Table ID and Record ID slug values are an exact match to the respective values in the API call url we just put in the overview tab. For the image paramter, take note of the slug as we will use it in the request tab.
Next, let’s configure the headers.
The values to place in the Key column can be referened from the header section of the API docs here.
For the Value column, you will want to add your app’s API keys. You can locate these values under Settings > API Keys in your app. If you don’t already have keys generated, you will want to generate those at this time.
Now for the request, this is where we’ll want to define the field we are going to set using this call. In this case, it will be the image field on the users table.
To set up the request, first, let’s define the Value on the right. This should show in brackets the slug for the image parameter that was set up earlier. Then, define the Key as the image field ID followed by [src]. In this example, the Key is field_82[src] because my image’s field ID is field_82.
To find the field ID of your image, open the field to edit in the data builder and it will be on the top right corner of the module. Be sure that you find the ID of the image that you would like to apply the default image to (in this example it is the field on the users table).
The last configuration to make for this call is going to be the response. This can be copied exactly from the image below. The call will return success when the call executes properly. In this example, we store the pipe return value in the text field added to the users table earlier and the value is mainly used as an indicator/confirmation that the pipe ran.
Now that we have the pipe call set up, the last step is to set up the table rule to run the pipe. Please reference the image below for details on the entire rule.
Let’s break down the portion that runs the pipe. The Table ID and Record ID parameters will be configured to be the given record’s Table ID and Record ID so these two parameters will look the same in your rule as it does in the image. As for the Image parameter, this is where the source URL of the default image to be applied should be placed.
Once this method is implemented, the default image will be uploaded to any new record where the image was left blank.