The file storage module provides REST APIs for file management. You can select the storage technology for the file management module. Each project can work with only storage technology. Currently supported storage technology are:
- Amazon S3
- Local Filesystem
You can currently do the following operaations in the file management module:
Configure the file storage module
The config pertaining to file management module can be found inside the
fileStore key under the
modules object. Here's the snippet:
modules: fileStore: enabled: true storeType: local conn: /tmp/data rules: rule1: prefix: / rule: create: rule: allow read: rule: allow delete: rule: allow # Config for other modules go here
fileStore you have to speicify the following fields:
- enable: Setting this field to
trueenables the file storage module.
- storeType: Choose the storage technology to back the file storage module. The possible options are
- conn: Connection is the region name for
amazon-s3and the root file path for
- rules: Are the security rules used to secure access to the file storage module. It's essentially a map which contains the
prefixon which to apply the rule.
The snippet shown above configues Space Cloud to use the local filesystem (
local). The files will be stored under the
/tmp/data directory. There is a single rule named
rule1 which allows all file storage operations (
delete). All rules are applied based on prefix matching on the URL.
Here's how you can add different rules for different prefixes.
modules: fileStore: enabled: true storeType: local conn: /tmp/data rules: imageRule: prefix: /images/:userId rule: create: rule: allow read: rule: allow delete: rule: allow musicRule: prefix: /music rule: create: rule: allow read: rule: allow delete: rule: allow # Config for other modules go here
allowrule must only be used cautiously. It must never be used for create and delete operations in production. You can read more about security rules for the files module here.
Now you know the basics of the file storage module. The next step would be diving deeper into the security rules and its structure. Let's make sure that the apps we build are secure!
You can also check out the API docs to start building your app right away or head over to the next module.