Saving Video to Realm Database using swift


#1

I am building video app like youtube in Swift with Realm. I want to store video files in database. Is it possible?
My app will work online.


#2

Possible? Yes. Recommended? No.
Storing large files is usually not recommended for any database. Databases are better used to store the meta data for the files and then a reference to the file system where the files are stored. It requires a bit more work, but gives you a better performing database.


#3

Hi.

Thanks for the reply but if trying to use realm cloud in storing video file it is really convenient?


#4

This will give you extremely poor user experience. Realm is not optimized to store large files in the database, so you’ll end up with poor performance and potentially much more expensive solution than relying on a dedicated storage service. As a few examples of why it’s not a good idea:

  • Realm streams data to/from the server in changeset (transaction) increments. Which means, that if connectivity is lost in the middle of a changeset upload, we’ll restart it the next time. Since videos are generally large and probably slow to upload/download, this could mean a lot more data will be used than necessary.
  • Realm stores a history of transactions on the server to be able to merge changes from other devices deterministically. This means that if a user uploads a video and then deletes it, this video will still consume space on the server until all clients that synchronized with that Realm confirm that they’ve seen this change.
  • On the device, Realm doesn’t support streaming data from the database, so if you want to play the video, you’ll need to copy the entire file in memory.

Obviously these are general concerns that may or may not apply to your use case. My recommendation would be to contact our sales team and outline the high-level requirements of your project so they can give you guidance on how to achieve that with Realm.