I have a TCP listener that listens multiple clients and gets logs and screenshot data from them which it later uploads to the database. I also have a flask API that fetches the data. I don't have any problem with the logs but I need some help regarding the best practices when it comes to saving image files.
b"{'username': 'example', 'computer': 'example', 'activity': 'screenshot', 'image': '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAC...', 'event_time': '2022-09-13T07:23:32.580592'}\n}"
This is an example byte object that I will receive. The "image" field is a base64 string. I know that saving the base64 string itself to the database is not recommended so I want to save them to the server as image files and then upload the path to the database. I then want to be able to fetch the individual images from the API when a request with the id of the image that will be generated by the database, is made. Is this a good approach? Also how should I name the files? Should I just generate a random string every time? I'd like to name the files as their database IDs but I won't have them until I save them to the database and I can't save them to the database until I have a path.