Navigation

Upload Content to Realm

On this page

Overview

You can upload content to MongoDB Realm from the Hosting screen of the Realm UI or by importing an application directory that includes the files. Select the tab below that corresponds to the method you want to use.

Procedure

1
2

Upload Files to Realm

You can upload files to MongoDB Realm individually or select multiple files or file directories to upload simultaneously. All files that you upload must be available on your local filesystem.

There are two ways to upload files through the Realm UI. You can use either of the following methods:

  • Drag and drop files from your local filesystem on to the Hosting screen.
  • Click Upload Files and select the files you wish to upload from a file picker.

Once you have dropped in or selected your files, Realm will begin uploading them immediately. The rate of upload time will vary depending on network connection speed and the number and size of the files selected.

1

Export Your Realm Application

To upload files to MongoDB Realm with realm-cli you need an application directory for your Realm app.

You can export your application from the Export tab of the Settings page in the Realm UI, or by running the following command from an authenticated instance of realm-cli:

realm-cli export --app-id=<App ID> --include-hosting
2

Add a Hosting Directory

Note

This step is only necessary if you did not export your Realm app with the --include-hosting flag.

MongoDB Realm looks for files to upload in the /hosting/files subdirectory of your application directory. If this directory doesn’t already exist, create it:

mkdir -p hosting/files
3

Add a Metadata Configuration File

To deploy hosted files through realm-cli you must include a metadata.json file in the /hosting directory. If the configuration file does not exist, create it:

touch hosting/metadata.json

The configuration does not need to specify metadata for any files but must be present. For more information, see Configure File Metadata.

metadata.json
[
  {
    "path": "<File Resource Path>",
    "attrs": [
       ...,
       <Attribute Definition>
    ],
  },
  ...
]
Field Description
path Required. The resource path of the file.
attrs

Required. An array of documents where each document represents a single metadata attribute. Attribute documents have the following form:

Metadata Attribute Document
{
  "name": "<Attribute Type>",
  "value": "<Attribute Value>"
}
Field Description
name The name of the metadata attribute. This should be one of the file metadata attributes that Realm supports.
value The value of the metadata attribute.

Note

If you include an entry in metadata.json for a file that does not exist, you will not be able to import your changes. The metadata.json must only have hosted files represented.

4

Add Files to the Hosting Directory

To upload or edit files, add them to the /hosting/files subdirectory of your application directory. When you import your application, MongoDB Realm will map this subdirectory to the root of your application’s hosted file tree.

Note

You can nest additional directories inside of the /hosting/files subdirectory. Nested directories are listed before a file’s name in its resource path.

5

Import the Files

Once you have added the files you want to host to the /hosting/files subdirectory, you can upload them to MongoDB Realm by importing your updated application directory with the --include-hosting flag:

realm-cli import --include-hosting

After successfully importing the application directory, MongoDB Realm will begin uploading your files. The rate of upload time will vary depending on network connection speed and the number and size of the files selected.