When users select multiple files, you may want to save each file separately in the Bubble database. This is achieved using an API Workflow executed "on a list," allowing each item to be processed individually.
Access Backend Workflows :
Open your application in the Bubble editor and go to the "Backend Workflows" tab (or "API Workflows").
Create a New Endpoint :
Click "New API Workflow" and name it, e.g., saveFile
.
Enable the option "Expose as a public API endpoint" so it can be called from other workflows.
Define Parameters :
Add the following parameters (configuring the correct type for each):
file_url
(text)file_id
(text)file_size
(number)file_name
(text)file_extension
(text)mime_type
(text)thumbnail
(text)Each parameter will represent a field of the file obtained from the picker.
Configure the Creation Action :
Inside the API Workflow, add a "Create a new thing" action.
Select the data type (e.g., "File," "Document," or the name of the table in the database).
Map each parameter to the corresponding fields of the record being created.
To execute the API Workflow on each item in a list:
In the Client-Side Workflow :
When the file_selected
event is triggered, add a "Schedule API Workflow on a List" action.
Select the List :
Specify the list of files to process. This list may come from an exposed state (e.g., selected_files
) containing objects with file fields.
Map Parameters :
For each parameter in the API Workflow, assign the corresponding value from the Current item's
list. For example:
file_url
: Current item's file_url
file_id
: Current item's file_id
file_size
: Current item's file_size
file_name
: Current item's file_name
file_extension
: Current item's file_extension
mime_type
: Current item's mime_type
thumbnail
: Current item's thumbnail
Suppose:
selected_files
, which is a list of objects. Each object includes: file_url
, file_id
, file_size
, file_name
, file_extension
, mime_type
, and thumbnail
.Steps:
Configure the API Workflow :
saveFile
file_url
, file_id
, file_size
, file_name
, file_extension
, mime_type
, thumbnail
.file_url
file_id
file_size
file_name
file_extension
mime_type
thumbnail
In the Client-Side Workflow :
file_selected
event is triggered, add the "Schedule API Workflow on a List" action.saveFile
selected_files
file_url
, file_id
, etc.) to the corresponding value of Current item's
.Data Validation :
Ensure that the data obtained from the picker is valid. Although the plugin includes validations, the API Workflow can include additional checks.
Error Handling :
Configure actions in the API Workflow to handle errors, such as notifying the administrator or retrying the operation in case of failure.
Scalability :
Using "Schedule API Workflow on a List" allows processing a large number of files independently on the server, avoiding client-side blocking.
Auditability :
Consider extending the API Workflow to log additional information about each operation, facilitating auditing and troubleshooting.
Testing :
Perform thorough testing to ensure each file is saved correctly in the database.
Was this page helpful?
Thank you for your feedback!
Please Login First
Comments (00)