0

I want to host images that users upload to a website.

However I don't know how to store this on a website dataBase. I know how to use SQL however it would seem to be a poor idea to store 1mb+ images on a SQL server.

My question is this: If you had a system with accounts that upload images, would you create some sort of file system on the web server and use that in tandem with a SQL database?

For example on the webserver you would create a /accounts folder that has thousands of folders which contain image files. Then use SQL queries and such to find user names and associated folders?

Sorry if this is a dumb question, I just don't know what to search to figure out more about this kind of topic.

  • Databases are very good at storing huge amounts of data/ Why would storing 1mb+ images be an issue? – John3136 Apr 12 '17 at 04:15
  • I've just read that storing JPEG files via SQL is a bad idea in terms of efficiency. Is this not true? –  Apr 12 '17 at 04:16
  • 1
    There are reasons for either approach. For instance, backup/restore - if you store images in the DB, your backups will include backups of the images, but your backups will be a lot bigger & longer to create/restore. If you store them in the file system, you can access them without extracting them from the DB into some interface - there's less code required, but you need to worry about orphaned records (files in the DB that don't exist on disk) - that can be tricky to maintain. – Max Szczurek Apr 12 '17 at 04:20
  • I wonder why google isn't useful for some people.. http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay http://stackoverflow.com/questions/1347461/saving-images-files-or-blobs – CurseStacker Apr 12 '17 at 05:57

1 Answers1

0

Storing images in the database is often a bad idea. There are a couple of ways it could be done depending on the scale of what you're trying to do.

The easiest way to manage would probably be to create a unique directory for each user, that way if it grows large, then you can split that across many storage devices, virtual servers and what have you. Then track the image information in the database by user.

Difster
  • 3,264
  • 2
  • 22
  • 32
  • So in short, you would use both a SQL server and server local directories right? –  Apr 12 '17 at 04:20
  • Yes, since you're probably going to want to track the images each user owns. You could reduce some overhead by making the image name the table index with a foreign key to the user id and then the rest of the image data that you might be tracking such as the title, date uploaded, etc. according to your needs. – Difster Apr 12 '17 at 04:23
  • Thanks for the response ! –  Apr 12 '17 at 04:24
  • You're welcome. Please mark the question as solved and give it an upvote if you could. Thanks! – Difster Apr 12 '17 at 04:26