Search code examples
realmrealm-mobile-platform

Best way to share blob with Realm Object Server


Realm Mobile Database had an limit for blob size of 16MB. According to document:

To store larger amounts of data, either break it up into 16MB chunks or store it directly on the file system, storing paths to these files in the Realm.

If we're going to use Realm Object Server to store our data, should we split the data into chunks? We do not expect to store video or disk image to Realm, but we can see users occasionally add large file.


Solution

  • The Realm Mobile Platform isn't necessarily made to store very large files. For example, 16MB is still a significant chunk of data to send over the air (especially on a 3G/4G connection).

    As EpicPandaForce indicated, you could host the file on a third party system, and store the authentication token in Realm alongside the URL. This system works fairly well with S3, which allows you to create a secret URL (with embedded access token) valid for x amount of time.

    This doesn't require a huge amount of work; it just requires proper management of your S3 buckets on the server-side. Using the Enterprise version of Realm Object Server, it's actually very easy to generate those URLs when the device requires it, and only when it requires it, for a short amount of time (typically, you would cache such large files on the device anyway, so you don't redownload them all the time).

    Alternatively, as the docs indicate, you can store everything as 16MB chunks. Please be aware that this might balloon your storage usage, as the actual Realm file will contain each 16MB chunk, but the transact log will also contain the same 16MB chunk (so that the merge algorithm can function properly on the server side).