R
R
Rinat2017-07-11 12:11:51
MySQL
Rinat, 2017-07-11 12:11:51

How to store photos in the database?

Tell those who know! I thought about how to store photos in the database on the server is Mysql.
Each photo will be discussed in comments and put likes. If you store everything in one table, there will be a lot of photo entries.
how to implement each user his own database of photos. For example

usersDATA
-------users1
-----------photobase
-----------comments
-------users2
--------- --photobase
-----------comments

can use an additional database on the server, and which one is better suited for storing such information
. UPD:
it seems that they misunderstood or I explained it wrong. Each user can have at least 100 photos. Every photo has likes and comments.
also, each user will have their own news where we selectively take users, get their news, sort by date.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Dmitry Gadzhiev, 2017-07-11
@gds1

no need to store photos in the database

K
Karen Mnatsakanyan, 2017-07-11
@karjan

Save the path to the photo in BD. not the photo itself.
It is logical for each usera to create their own table in which there is a photo cell, and displays from there and not each comment to save the photo.

F
Fixid, 2017-07-11
@Fixid

Do not store photos in the database, store them in a folder on disk by uuid, and store a unique URL in the database. This is normal practice.
Do not reinvent the wheel, you will get an overhead 5-7 times at least, and as soon as you have a base of 2-3 GB, everything will slow down.
Ideally, you need to get a very small database of two simple tables and a folder structure where you can store as many photos as you like with feedback via a web server

M
Maxim Grishin, 2017-07-11
@vesper-bot

It is necessary to move the photo to a separate table of the type (id, blob) in the blob to store binary data, or if it breaks, then the path to the actual storage location, and use the id in other places where you need to refer to the pictures. Comments - also in a separate table, likes - in another one.

S
sim3x, 2017-07-11
@sim3x

User:
  name
  ...

UserPhoto
  owner = ForeignKey(User)
  path_to_photo_on_disk
  likes = ManyToMany(User)

Comment
  user = ForeignKey(User)
  photo = ForeignKey(UserPhoto)
  text
  datetime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question