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

examples: add CORS settings for DigitalOcean Spaces #4428

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/digitalocean-spaces/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Uploading to DigitalOcean Spaces

This example uses Uppy to upload files to a DigitolOcean Space. DigitalOcean Spaces has an identical API to S3, so we can use the [AwsS3](https://uppy.io/docs/aws-s3) plugin. We use @uppy/companion with a [custom `endpoint` configuration](./server.cjs#L39) that points to DigitalOcean.
This example uses Uppy to upload files to a [DigitalOcean Space](https://digitaloceanspaces.com/).
DigitalOcean Spaces has an identical API to S3, so we can use the
[AwsS3](https://uppy.io/docs/aws-s3-multipart) plugin. We use @uppy/companion with a
[custom `endpoint` configuration](./server.cjs#L39) that points to DigitalOcean.

## Running it

Expand All @@ -14,14 +17,24 @@ corepack yarn build
That will also install the dependencies for this example.

First, set up the `COMPANION_AWS_KEY`, `COMPANION_AWS_SECRET`,
`COMPANION_AWS_REGION`, and `COMPANION_AWS_BUCKET` environment variables for
`COMPANION_AWS_REGION` (use a DigitalOcean region name for `COMPANION_AWS_REGION`,
e.g. `nyc3`), and `COMPANION_AWS_BUCKET` environment variables for
`@uppy/companion` in a `.env` file. You may find useful to first copy the
`.env.example` file:

```sh
[ -f .env ] || cp .env.example .env
```

To setup the CORS settings of your Spaces bucket in accordance with
[the plugin docs](https://uppy.io/docs/aws-s3-multipart/#setting-up-your-s3-bucket),
you can use the [example XML config file](./setcors.xml) with the
[`s3cmd` CLI](https://docs.digitalocean.com/products/spaces/reference/s3cmd/):

```sh
s3cmd setcors examples/digitalocean-spaces/setcors.xml "s3://$COMPANION_AWS_BUCKET"
```

Then you can start the dev server:

```bash
Expand Down
15 changes: 15 additions & 0 deletions examples/digitalocean-spaces/setcors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>http://localhost:3452</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<ExposeHeader>ETag</ExposeHeader>
<AllowedHeader>Authorization</AllowedHeader>
<AllowedHeader>Content-Type</AllowedHeader>
<AllowedHeader>x-amz-date</AllowedHeader>
<AllowedHeader>x-content-sha256</AllowedHeader>
</CORSRule>
</CORSConfiguration>