Reputation: 1
I created a script that uploads files and saves them into a SQL database as binary data. Is it better to upload them to folders on the server and saving only a link to them in the database?
If yes, how can I do that ?
Upvotes: 0
Views: 3074
Reputation: 2171
This depends on size of files that you expect to be uploaded to your server as well as number of these files and how often image data will be requested from the server.
If your files are small enough, then storing them in DB will allow you to use built-in SQL Server data integrity mechanics. Your database backups will be automatically synchronized with image data. However big files will make your database 'heavy'.
If you choose to store files in DB, then it's good to create specialized table for images. The benefit of storing images in a separate table is that the requests to this dedicated table will occur only when necessary (for instance, when user requests image author and time image was created, the DB server will use lightweight table with image metadata). Another benefit is that some databases (MS SQL) allow to put tables on different disks, so you can put this heavy table on a separate disk.
If you are choosing to store only links to image files, then you need to implement data integrity yourself. You will need to backup images when doing database backup. You will need to ensure that there are no links in DB that point to non-existent files and there are no files that do not have links in DB etc. This option makes your DB lightweight, but requires additional coding and maintenance.
Upvotes: 1
Reputation:
Yes, as I think. This article maybe useful http://www.shabdar.org/sql-server/105-store-save-images-in-sql-server.html
Upvotes: 0