File Manager
<bk-file-manager></bk-file-manager>
Manages file upload transactions by holding a unique transaction ID hash map. Since files are often linked to a collection entry but stored on a different service, it might be handy to control file upload through a transaction manager. Two steps are needed to successfully upload a file:
- handle file uploads to a storage service. Assuming a backend service such as Mia Platform's Files Service, a component like the File Service Client could perform such task.
- handle updates to the CRUD collection. Assuming a backend service such as Mia Platform's CRUD Service, this task could be handled by the CRUD Client.
The File Manager component processes requests originating from other components to create or update data in a CRUD collection, which also require operations involving uploading files to a designated file storage service. The requests that trigger these actions are typically in the form of create-data-with-file or update-data-with-file events.
These events encapsulate both the data to be created or updated and additional information within their meta section. The meta data aids in extracting the files that require uploading from the payload.
The flow of this process can be summarized as follows:
- The File Manager identifies within the payload all files that should be uploaded.
- For each identified file, the File Manager initiates an upload request to the designated file storage service.
- Upon receiving notifications confirming successful file uploads, the File Manager proceeds to signal the request for creating or updating data using the complete payload from the initial triggering event.
- However, in the event of an error notification being received, the entire transaction is retracted. This includes deleting any files that were already uploaded as part of the incomplete transaction.
Further details on how Back-Kit components can be composed to handle file fields are available in the specific section.
How to configure
The File Manger does not require any configuration.
{
"tag": "bk-file-manager"
}
API
Properties & Attributes
None
Listens to
event | action | emits | on error |
---|---|---|---|
update-data-with-file | initiates an upload file transaction attaching a unique ID and attempting upload file to the storage service | upload-file | - |
create-data-with-file | initiates an upload file transaction attaching a unique ID and attempting upload file to the storage service | upload-file | - |
uploaded-file | continues a create-data-with-file or update-data-with-file transaction by patching the CRUD collection with the upload-file metadata | update-data,create-data | - |
error | interrupts a registered transaction due to an occurred error event carrying a meta . If the file was stored but the collection wasn't successfully patched, then the file is deleted | delete-file | - |
Emits
event | description |
---|---|
upload-file | contains file and metadata to be stored |
update-data | after storage, contains reference metadata used to patch a collection containing reference to such file |
create-data | after storage, contains reference metadata used to create an item into collection containing reference to such file |
create-data | after storage, contains reference metadata used to create an item into collection containing reference to such file |
delete-file | contains file metadata to trigger file deletion |