Prerequisites:
I have a chat application, on this site, among other things, it is possible to send messages with attachments. Initially, I created this functionality only using Websockets. In other words, both text, and files send over Websocket together.
Problem:
So, I understood, that the abovementioned approach is not good. I wanna send files over HTTP(S). It will help:
- Improve UI – it will be able to show uploading status
- To get rid of Websocket limitations when transferring large files
The main trouble to me is to link text(and other data, such as reply_message_id) and files.
Question:
How do I link the message text and files on the server side, given that all message data, with the exception of files, will be transmitted via Websocket, and files via HTTP(S)?
A possible way to solve the problem:
- As soon as I select one or more files, they are immediately sent to the server. It will be impossible to send a message until the files are uploaded to the server.
- Connect file records with the new empty message in the DB. Also I have to create a boolean flag to check whether the messege are processing or ready
- (Return the new message Id and then, when the user will send a messege, add this message Id to the data)
OR
(Return the ID of each file and, att tthe time of sending the message, add thefiles
field, which will contain an Array of these IDs) - Change “is_message_processing” flag. Update rest of the data, such as: text, reply_to_messege_id, forwarded_message_id, etc.
Maybe you know better ways to solve this problem, or have you already encountered this problem?
Thanks for your time, I appreciate it.