A unique and powerful feature included with the Files API and IPFS API is the key-value store. Anytime you upload or update a file you can store up to 10 key-value pairs.

This small yet powerful feature allows you to remove the need for an external database in most cases. We like to call this paradigm File-Centric Architecture, where apps and their structure revolves around the files themselves. This creates a molecule like structure and keeps the data related to the file close by.

Creating

Creating a new key-value for a file can be done in two ways:

Uploading a File

By including the key-values as part of the upload method or endpoint and the file and the key-values will be created at the same time.

Updating an Existing File

If you’ve already uploaded a file and want to add a key-value you can do so with the update method or endpoint.

Retrieving

Since key-values exist with files, you can retrieve them by listing files either through the SDK method or API endpoint, and filtering results by key-value. The operator will always be ===.

You can chain multiple key-value queries together and it will only return files that meet both values.

Updating

The Files API key-value system will automatically detect if you are replacing an existing value for a given key. For example, if you have a key of env with a value of prod, if you make an update of env: "dev" it will replace the old value. If the key does not exist then it will make a new key-value entry.

Deleting

You can remove a key-value entry by making the value null.

Further Reading

Check out some of our reading material on some of the possibilities of key-values and file-centric architecture!