store image in database or in a system file? [closed]
Asked Answered
A

4

9

Exact Duplicate: User Images: Database or filesystem storage?
Exact Duplicate: Storing images in database: Yea or nay?
Exact Duplicate: Should I store my images in the database or folders?
Exact Duplicate: Would you store binary data in database or folders?
Exact Duplicate: Store pictures as files or or the database for a web app?
Exact Duplicate: Storing a small number of images: blob or fs?

I have to store user's profile image (100px * 100px) what is the best way to store it ? database or system file ? which one is better , faster ,safer ... ?

Asci answered 19/4, 2009 at 20:34 Comment(7)
@Yassir, seriously man. Search. I found 6 duplicates in seconds. I know there are more.Harbin
oh sry they didn't appear when i was typing the question my bad it won't happen againAsci
"Closed as spam"?!? I can understand closed as duplicate, but why spam?Crinkle
Yeah, doesn't seem like spam to me, either.Silkworm
Well, Yassir himself voted to close. So maybe he mis-clicked.Ellita
Just for the record, I voted to close as exact dupe... WBN if the close votes were broken down by closer.Melamine
sry again i missed click it :S i m not familiar with SO yet :SAsci
N
12

Always store images, music files etc in system files on disk, and then store the url:s to them in the database. That will make it

1) faster

2) easier to configure security settings

3) better in any ways I can imagine

Neutralization answered 19/4, 2009 at 20:40 Comment(6)
but wouldn't i have a problem when i back-up data ?Asci
No - just as there are backup solutions for databases, there are backup solutions for system files. Of course, depending on the scale of your appication, a third-party service like James Avery proposes could be what you're looking for. But unless you're going huge-scale with images, I would definitely recommend system files.Neutralization
@TomasAschan how to retrieve the data from the file system?Kenzi
@user7098526: You can read it from the file system using e.g. the APIs in System.IO.File. However, this answer is from 2009 - the landscape has changed a lot since then. Today, I'd recommend hosting any type of files in something like AWS S3 or Azure Blob Storage, rather than rolling your own.Neutralization
Thanks Tomas. Can you please suggest suggest some article to read on this?Kenzi
@user7098526: The internet is full of them. Just look for "getting started with" + whatever product you want to use :)Neutralization
E
12

SQL Server 2008 offers the best of both worlds.

Erbil answered 19/4, 2009 at 20:44 Comment(1)
This was the answer for me. I was looking for an already-implemented file repository that stores on the filesystem but is managed through the DB.Unicuspid
V
9

I am going to propose a third option, a third-party party place like Amazon S3 or Mosso Cloud Files. Both provide APIs that you can use to upload the file and both provide CDN capabilities so the files will load quicker then they would off your servers or pulling from your database.

This is a nice option because it is the best of both worlds. The downside of storing images in the database is that it is additional stress on your application and database servers (locating the file and pulling it) and it also causes your database to grow in size which can mean you will need more hardware earlier.

The downside of storing them in the file system is that you now have an issue with scaling as if you want to add additional web servers they would each need a copy of the image or you would need create a dedicated server for these images. Also, file system access could be a future bottleneck to worry about.

Vapid answered 19/4, 2009 at 20:42 Comment(0)
A
4

database makes it easier to backup and restore and it works better than file system storage for small images. Microsoft had published a research paper on this topic: To BLOB or Not To BLOB.

Anglian answered 19/4, 2009 at 20:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.