1

I am looking forward to build an application where users must upload their multimedia data onto a database such as images, videos and sound recording (attachments). What is the best way to store and retrieve this type of data?

Is it safe for example to use LONGBLOB on mySQL?

  • Do you have to store them in the database, would the filesystem be a better alternative (although not sure what better is :-/) – Nigel Ren Jul 23 '19 at 06:33
  • Database file storage would be inefficient, as you'd be requesting the image every time instead of using the users cache for already downloaded pictures. – Gary Hayes Jul 23 '19 at 06:36
  • Could you provide an example of a file system server (documentation), please? – christianilvi Jul 23 '19 at 06:38
  • You would just store the image, "image.jpg" in a folder and point to it in the database. – Gary Hayes Jul 23 '19 at 06:43

4 Answers4

2

Don't store them in a database.

Consider using Amazon S3 or some other type of cloud filesystem, and store the path of the file in your database.

Note:

It probably isn't the best practice to store the entire path in your database,

  • just store the local path of the file in your database
  • store the bucket address in your environment variables,
  • then dynamically generate the URL to load and access the file.
Malay M
  • 1,659
  • 1
  • 14
  • 22
Haolin
  • 161
  • 5
1

Don't store those type of files directly in database. Here's why Storing Images in DB - Yea or Nay?

Store those files in cloud storage and store path to those files in database

This one is free cloud storage

https://cloudinary.com/pricing?utm_expid=.Gmty0F1bRCaIqeSDwI0cEQ.0&utm_referrer=https%3A%2F%2Fcloudinary.com%2F

Or try using AWS or GCP bucket storage services.

Phootip
  • 156
  • 1
  • 12
1

It is possible but not recommended to store the objects in database, however if the objects are very small, and the application is small you could store them in database.

It is a good practice to store the object files in some object container like AWS S3 or GCP Bucket

Malay M
  • 1,659
  • 1
  • 14
  • 22
  • Let's say I use the GCP, is there any way to link a mySQL database record to the image (for example: to eliminate two images having the same url - there would be a column called 'path' in the table) – christianilvi Jul 23 '19 at 07:02
  • You could add a. **current timestamp** or b. **some random number** or the c. **profile id** or combination of both as a prefix and rename the file. then keep the copy of reference in database. – Malay M Jul 23 '19 at 07:06
0

Yes. As long as it's not a large file. Because database will significantly slow down database access

Blueberry
  • 31
  • 10