What Matt H offers is a good idea if what you are trying to achieve is user-level access to images. But assuming you are limited in storage stored in the database, storing images in binary data is inefficient, as you stated.
Using a table for the user is a poor design. The user who uploaded the file should simply be a field / column in the table in which all file downloads are stored, as well as any file metadata. I suggest creating a GUID for the file name, which is guaranteed to be unique and better than the auto-increment field, which is easy to guess if you are trying to prevent users from simply accessing all images.
You are concerned about performance, but as long as you are not dealing with millions and millions of records, your image selection requests are owned by the user, downloaded in a certain period of time (for example, you save a time stamp or the like) are insignificant in cost. If speed is a problem, you can add a B-tree index to the username, which will greatly speed up your user requests.
Back to the topic of security, access and organization. Store images with a folder per user (although depending on the number of users, the number of folders may increase to an unmanageable level). If you do not want the images to be publicly available, save them in a non-web folder, ask the application to read the data and transfer it to render the image to the user. More complicated, but you are hiding the actual file from the Internet. In addition, you can check all image requests with an authenticated user.
achinda99
source share