Skip to content
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

add s3 adapter examples for Linode and Backblaze #825

Merged
merged 9 commits into from
Apr 21, 2022
102 changes: 61 additions & 41 deletions _includes/parse-server/file-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ var api = new ParseServer({

Don't forget to change **S3_ACCESS_KEY**, **S3_SECRET_KEY** and **S3_BUCKET** to their correct value.

##### S3Adapter constructor options
### Adapter Options

```js
new S3Adapter(accessKey, secretKey, bucket, options)
Expand All @@ -194,6 +194,66 @@ new S3Adapter(accessKey, secretKey, bucket, options)
| baseUrlDirect | Key in `options`. Is `true` if the file adapter should ignore the bucket prefix when determining the file location for direct access. | Optional. Default: `false`. To be used when `directAccess=true` and `baseUrl` is set. When set to `true`, the file adapter returns a file URL in format `baseUrl/filename`. Example for `baseUrl='http://domain.com/folder'` and `baseUrlDirect=true` the returned file location is `http://domain.com/folder/file.txt`. |
| globalCacheControl | Key in `options`. The `Cache-Control` http header to set in the file request. | Optional. Default: `null`. Example: `public, max-age=86400` for 24 hrs caching. More info [here](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1). |

### S3-compatible Services
#### Digital Ocean Spaces

[Digital Ocean Spaces](https://try.digitalocean.com/cloud-storage) is an S3-compatible storage service in the cloud. See their [documentation](https://docs.digitalocean.com/products/spaces/) for more details.

```javascript
const s3Options = {
bucket: "SPACES_BUCKET_NAME",
baseUrl: "SPACES_BASE_URL",
region: "SPACES_REGION",
directAccess: true,
alioguzhan marked this conversation as resolved.
Show resolved Hide resolved
globalCacheControl: "public, max-age=31536000",
bucketPrefix: "SPACES_BUCKET_PREFIX",
s3overrides: {
accessKeyId: "SPACES_ACCESS_KEY",
secretAccessKey: "SPACES_SECRET_KEY",
endpoint: 'SPACES_ENDPOINT'
}
};
```

#### Linode Object Storage

[Linode Object Storage](https://www.linode.com/products/object-storage/) is an S3-compatible storage service in the cloud. See their [documentation](https://www.linode.com/docs/guides/how-to-use-object-storage/) for more details.

```js
const s3Options = {
bucket: "S3_BUCKET_NAME",
baseUrl: "S3_BASE_URL", // https://myBucket.myRegion.linodeobjects.com
region: "S3_REGION", // possible values: eu-central-1 or us-east-1
directAccess: false,
s3overrides: {
accessKeyId: "S3_ACCESS_KEY", // bucket access key
secretAccessKey: "S3_SECRET_KEY", // bucket secret key
endpoint: "S3_ENDPOINT", // regionName.linodeobjects.com
},
};
```

#### Backblaze B2 Cloud Storage

[Backblaze B2 Cloud Storage](https://www.backblaze.com/b2/cloud-storage.html) is an S3-compatible storage service in the cloud. See their [documentation](https://www.backblaze.com/b2/docs/) for more details.

```js
const s3Options = {
bucket: "S3_BUCKET",
directAccess: true,
baseUrl: "S3_BASE_URL", // taken from BackBlaze, normally https://BUCKET.s3.REGION.backblazeb2.com
baseUrlDirect: false,
signatureVersion: 'v4',
globalCacheControl: 'public, max-age=86400',
region: 'us-west-000',
s3overrides: {
endpoint: "S3_ENDPOINT", // check backblaze bucket endpoint
accessKeyId: "S3_ACCESS_KEY",
secretAccessKey: "S3_SECRET_KEY"
},
};
```


## Configuring `GCSAdapter`

Expand Down Expand Up @@ -249,46 +309,6 @@ var api = new ParseServer({
});
```

##### S3Adapter configuration for Digital Ocean Spaces

Spaces is an S3 equivalent prodivided by Digital Ocean. It's use the same api as S3 so you can use it with the S3 Adapter.
You just need to change the AWS Endpoint to point to your Spaces endpoint.

```javascript
...
var S3Adapter = require('parse-server').S3Adapter;
var AWS = require("aws-sdk");

//Set Digital Ocean Spaces EndPoint
const spacesEndpoint = new AWS.Endpoint(process.env.SPACES_ENDPOINT);
//Define S3 options
var s3Options = {
bucket: process.env.SPACES_BUCKET_NAME,
baseUrl: process.env.SPACES_BASE_URL,
region: process.env.SPACES_REGION,
directAccess: true,
globalCacheControl: "public, max-age=31536000",
bucketPrefix: process.env.SPACES_BUCKET_PREFIX,
s3overrides: {
accessKeyId: process.env.SPACES_ACCESS_KEY,
secretAccessKey: process.env.SPACES_SECRET_KEY,
endpoint: spacesEndpoint
}
};

var s3Adapter = new S3Adapter(s3Options);

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
appId: process.env.APP_ID || 'APPLICATION_ID',
masterKey: process.env.MASTER_KEY || 'MASTER_KEY',
...
filesAdapter: s3Adapter
...
});
```


##### GCSAdapter constructor options

```js
Expand Down