From 421a9ad25ac5a839ebb4c82c0930f65190aa72e7 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 25 Apr 2023 18:08:38 +0200 Subject: [PATCH] examples: add CORS settings for DigitalOcean Spaces --- examples/digitalocean-spaces/README.md | 17 +++++++++++++++-- examples/digitalocean-spaces/setcors.xml | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 examples/digitalocean-spaces/setcors.xml diff --git a/examples/digitalocean-spaces/README.md b/examples/digitalocean-spaces/README.md index 5d570b966e..b17b0f6a22 100644 --- a/examples/digitalocean-spaces/README.md +++ b/examples/digitalocean-spaces/README.md @@ -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 @@ -14,7 +17,8 @@ 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: @@ -22,6 +26,15 @@ First, set up the `COMPANION_AWS_KEY`, `COMPANION_AWS_SECRET`, [ -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 diff --git a/examples/digitalocean-spaces/setcors.xml b/examples/digitalocean-spaces/setcors.xml new file mode 100644 index 0000000000..3159dbf37a --- /dev/null +++ b/examples/digitalocean-spaces/setcors.xml @@ -0,0 +1,15 @@ + + + + http://localhost:3452 + GET + POST + PUT + 3000 + ETag + Authorization + Content-Type + x-amz-date + x-content-sha256 + +