-
Notifications
You must be signed in to change notification settings - Fork 0
File attachments
Table of contents
[[TOC]]
System should allow to attach file of any type to existing message or create message with attachments.
On messenger side it's required to save metadata for attachments. New field attachments
will be added for messages as list of entries with following format:
-
uid
- unique id for file within message; -
name
- original filename on upload; -
type
- content type of the file; -
size
- size of file; -
thumbUrl
- url of thumbnail (if available); -
fileUrl
- direct url for download;
For saving files it's required to create new unit. It will allow to upload files, keep track of them and get via direct call.
To maintain transactional nature of system storage unit will allow to upload files without any additional checks. But new uploaded files will not be available by direct link.
Proposed flow of creating entity with attachments:
- System receives entity with list of files in multipart request;
- Logic should generate attachment list based on list of files from request with random generated
uid
fields. Attachment list must be included in wrapper with entity type. Files should be repackeged to new multipart request and be sent to storage unit for saving; - Storage unit should save supplied files and save metadata in attachment list to db;
- System should proceed to create entity;
- After entity creation responsible unit should send message to commit file attachments;
- In case of error during entity creation uncommited files on storage unit should be erased by separate job by schedule;
- On commiting files storage unit should generate permanent links and send it via notification (
fileUrl
and TBDthumbUrl
);
File URL should be generated by following template: {storegeUrl}/{entityType}/{entityId}/{name}
. Storage URL should be configured on unit itself and should be available for outside.
- It's unknown how to configure multiple storage units for load balancing. Possible solutions:
- Keep one instance;
- Use MessageBus to resolve addpress and port for storage unit. But in this case it's required to configure API to upload file on same javalin instance as MessageBus;
- Use MessageBus to upload files. Requires to attach files to messages;
- Limiting access to files. It's no viable to leave unlimited access.