Reputation: 816
i am trying to store image in sql on server. Later i want to make these image available for download. Which approach is good:
Upvotes: 0
Views: 133
Reputation: 8156
If the security
is main concern then store image in DB
in blob
, or if if it is not much sensitive then store it in specific directory then store it's path in DB
.
Because DB storage give it extra security
.
If we store it on directory then someone can access it if they have tried some trick to access the directory.
So, and if we store it on directory then proper handling
of file should be done.
Because if someone upload file then again other person store it wit same name
then possibility of file overwrite
.
So you can do something like that take 2 fields
in table one is original name
and one is new name that have original name plus the timestamp of file upload
and in directory store it with that new name
.
and if you are storing it in DB then doesn't need this extra work.
And yes bifurcation of images in directory also tough, suppose in one year so many file will be stored in it so indexing plus accessing become cumbersome work. So apply some mechanism so at some time of interval you can separate images.
Upvotes: 1
Reputation: 4770
I'd say it's a tradeoff, and it also depends a lot on your network connection, I'd go for keeping the images in the cloud and just keeping a key in the database.
It would shrink the disk usage a lot , possibly even allowing the entire database to be cached into ram, thus balancing the extra time the process would spend retrieving the relevant info from the network
Upvotes: 1