File Save
How to give your users the option to upload a file into your system.
Last updated
How to give your users the option to upload a file into your system.
Last updated
In this tutorial we are going to teach you how to create a file upload feature for your users. To do this we will use two events that we combine together: the Create Event & the File Save Event.
The first step is to create a new action. To do this, go to the actions tab & click . Give your new action a sensible name & set your action trigger to "Endpoint".
Next you, update the endpoints settings. The final settings for your endpoint should look like the screenshot below. Notice that the Request Method is set to Post & that the Request Response Type is set to multipart/form-data.
The next step is to add a body variable to your endpoint. This body variable will be used to pass the file into the endpoint. To do this, click the yellow button to the left of the body variable field, select the variable type "File" and give it a name and label such as "input", as shown below.
** NOTE ** the input variable must be a body variable, it cannot be a header, path or query variable.
If you want to send other information to your endpoint, such as the name of the file, you can send this as a query variable. This is shown in the example below.
In this step, I am going to show you how you can add a create event & a file save event to add a new record to save down the name of your file & the file that you want to save. The database we will be using for this step is shown below. Notice that there are two custom fields, file name, of type text & file of type attachment.
After adding the create event, the next step is to use the Create Event options to select the Data Model & the field in the data model that you want to create the file name for. In our case, this will be the Files Data Model & the field will be the file_name field. This is shown below.
Lastly, you need to (1) set the value that you want to assign to the file_name (this will be the value that is passed into the trigger endpoint, from your query variable), (2) Set the event return variable field and (3) save your Create Event configuration. These steps are shown below.
Next, use the File Save Event options to:
Choose the File that you want to save, This will be the File variable passed into your endpoint.
Choose the File Path that you want to use. This will be the filePath variable used in your query variable).
Set the Object. The Object is the row of data that you will attach the new file to. This new row will be the new row of data that we created in the previous step, which we called file path name.
Set the Property, this is the column that you want to store the data in, in our case this is our column file of type attachments.
These steps are shown below.
Step 1. Choosing the File that you want to save.
Step 2. Choose the File Path.
Step 3. Set the Object.
Step 4. Set the Property.
In order to save down the file name, we need to add a create event to our Action. To do this click on inside of your action & select the event type "Create" from under the section Database Requests.
The final step is to save down the File that you want to upload to an attachments column in the database. To do this, click & add a file save event, from under the Files section, as shown below.
Finally, click to save down your configuration. The final Action & Event chain is shown below for your reference. You can now build your code & test your action in the normal way.