Skip to content

File Upload Docs #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 14, 2022
40 changes: 34 additions & 6 deletions _includes/parse-server/file-adapters.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Configuring File Upload

*Available only on Parse Server starting 5.0.0*

Parse Server restricts file upload to authenticated users only to improve Parse Server's default security. This behaviour can be modified by specifying `fileUpload` options to your Parse Server configuration.

Available options are:

`enableForAnonymousUser`: Whether file upload should be allowed for anonymous users
`enableForAuthenticatedUser`: Whether file upload should be allowed for authenticated users
`enableForPublic`: Whether file upload should be allowed for public users

To allow public file uploads to Parse Server:

```javascript
const api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.PARSE_SERVER_CLOUD || __dirname + '/cloud/main.js',
appId: process.env.PARSE_SERVER_APPLICATION_ID || 'myAppId',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
fileUpload: {
enableForPublic: true,
enableForAnonymousUser: true,
enableForAuthenticatedUser: true,
}
});
```

# Configuring File Adapters

Parse Server allows developers to choose from several options when hosting files:
Expand All @@ -23,7 +51,7 @@ File encryption is available in parse-server 4.4.0+. The `GridStoreAdapter` can
To use, simply do any of the following:
- Use the environment variable `PARSE_SERVER_ENCRYPTION_KEY`
- Pass in --encryptionKey in the command line when starting your server
- Initialize ParseServer with `encryptionKey="Your file encryptionKey"`.
- Initialize ParseServer with `encryptionKey="Your file encryptionKey"`.

An example starting your Parse Server in `index.js` is below:

Expand All @@ -32,13 +60,13 @@ const api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.PARSE_SERVER_CLOUD || __dirname + '/cloud/main.js',
appId: process.env.PARSE_SERVER_APPLICATION_ID || 'myAppId',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
encryptionKey: process.env.PARSE_SERVER_ENCRYPTION_KEY, //Add your file key here. Keep it secret
...
});
```

Be sure not to lose your key or change it after encrypting files.
Be sure not to lose your key or change it after encrypting files.

### Enabling encryption on a server that already has unencrypted files
When this is the case, it is recommended to start up a development parse-server (or a separate process from your main process) that has the same configuration as your production server. On the development server, initialize the file adapter as above with the new key and do the following after initialization in your `index.js`:
Expand Down Expand Up @@ -69,7 +97,7 @@ const api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.PARSE_SERVER_CLOUD || __dirname + '/cloud/main.js',
appId: process.env.PARSE_SERVER_APPLICATION_ID || 'myAppId',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
//No encryptionKey here
...
});
Expand Down Expand Up @@ -345,7 +373,7 @@ var api = new ParseServer({
})
```

Be sure not to lose your key or change it after encrypting files.
Be sure not to lose your key or change it after encrypting files.

### Enabling encryption on a server that already has unencrypted files
When this is the case, it is recommended to start up a development parse-server (or a separate process from your main process) that has the same configuration as your production server. On the development server, initialize the file adapter as above with the new key and do the following after initialization in your `index.js`:
Expand Down Expand Up @@ -376,7 +404,7 @@ const api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.PARSE_SERVER_CLOUD || __dirname + '/cloud/main.js',
appId: process.env.PARSE_SERVER_APPLICATION_ID || 'myAppId',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
masterKey: process.env.PARSE_SERVER_MASTER_KEY || '',
filesAdapter: new FSFilesAdapter(), //No encryptionKey supplied
...
});
Expand Down