diff --git a/.env.example b/.env.example index a1ea58cc7..364b7e3e0 100644 --- a/.env.example +++ b/.env.example @@ -26,6 +26,8 @@ COMPANION_AWS_REGION="AWS REGION" COMPANION_AWS_PREFIX="OPTIONAL PREFIX" # to enable S3 Transfer Acceleration (default: false) # COMPANION_AWS_USE_ACCELERATE_ENDPOINT="false" +# to enable S3 path style uploads (default: false), this is useful for localstack support +# COMPANION_AWS_FORCE_PATH_STYLE="true" # to set X-Amz-Expires query param in presigned urls (in seconds, default: 800) # COMPANION_AWS_EXPIRES="800" # to set a canned ACL for uploaded objects: https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl diff --git a/docs/companion.md b/docs/companion.md index c27063a17..f06292761 100644 --- a/docs/companion.md +++ b/docs/companion.md @@ -501,6 +501,12 @@ the following arguments: - metadata provided by the user for the file (will be `undefined` for local uploads) +#### `s3.forcePathStyle` `COMPANION_AWS_FORCE_PATH_STYLE` + +This adds support for setting the S3 client’s `forcePathStyle` option. That is +necessary to use Uppy/Companion alongside localstack in development +environments. **Default**: `false`. + ##### `s3.region` `COMPANION_AWS_REGION` The datacenter region where the target bucket is located. diff --git a/examples/aws-companion/server.cjs b/examples/aws-companion/server.cjs index 98dc31231..cf2b84357 100644 --- a/examples/aws-companion/server.cjs +++ b/examples/aws-companion/server.cjs @@ -35,6 +35,7 @@ const options = { bucket: process.env.COMPANION_AWS_BUCKET, region: process.env.COMPANION_AWS_REGION, endpoint: process.env.COMPANION_AWS_ENDPOINT, + forcePathStyle: process.env.COMPANION_AWS_FORCE_PATH_STYLE === 'true', }, server: { host: 'localhost:3020' }, filePath: DATA_DIR, diff --git a/examples/aws-nodejs/index.js b/examples/aws-nodejs/index.js index c067565d5..cb8c42cb1 100644 --- a/examples/aws-nodejs/index.js +++ b/examples/aws-nodejs/index.js @@ -61,6 +61,7 @@ function getS3Client () { accessKeyId: process.env.COMPANION_AWS_KEY, secretAccessKey: process.env.COMPANION_AWS_SECRET, }, + forcePathStyle: process.env.COMPANION_AWS_FORCE_PATH_STYLE === 'true', }) return s3Client } diff --git a/examples/digitalocean-spaces/server.cjs b/examples/digitalocean-spaces/server.cjs index dc369fa8b..e6d10ce97 100644 --- a/examples/digitalocean-spaces/server.cjs +++ b/examples/digitalocean-spaces/server.cjs @@ -14,6 +14,7 @@ const companion = require('../../packages/@uppy/companion') * - COMPANION_AWS_KEY - Your access key ID * - COMPANION_AWS_SECRET - Your secret access key * - COMPANION_AWS_BUCKET - Your space's name. + * - COMPANION_AWS_FORCE_PATH_STYLE - Indicates if s3ForcePathStyle should be used rather than subdomain for S3 buckets. */ if (!process.env.COMPANION_AWS_REGION) throw new Error('Missing Space region, please set the COMPANION_AWS_REGION environment variable (eg. "COMPANION_AWS_REGION=ams3")') @@ -43,6 +44,7 @@ const { app: companionApp } = companion.app({ secret: process.env.COMPANION_AWS_SECRET, bucket: process.env.COMPANION_AWS_BUCKET, region: process.env.COMPANION_AWS_REGION, + forcePathStyle: process.env.COMPANION_AWS_FORCE_PATH_STYLE === 'true', }, server: { host }, filePath: DATA_DIR, diff --git a/packages/@uppy/companion/env_example b/packages/@uppy/companion/env_example index 89e7b2298..08b3e0acf 100644 --- a/packages/@uppy/companion/env_example +++ b/packages/@uppy/companion/env_example @@ -39,6 +39,7 @@ COMPANION_AWS_BUCKET= COMPANION_AWS_ENDPOINT= COMPANION_AWS_REGION= COMPANION_AWS_PREFIX= +COMPANION_AWS_FORCE_PATH_STYLE="false" COMPANION_ZOOM_KEY= COMPANION_ZOOM_SECRET= diff --git a/packages/@uppy/companion/src/server/s3-client.js b/packages/@uppy/companion/src/server/s3-client.js index d5b5c48be..74717d238 100644 --- a/packages/@uppy/companion/src/server/s3-client.js +++ b/packages/@uppy/companion/src/server/s3-client.js @@ -29,6 +29,7 @@ module.exports = (companionOptions, createPresignedPostMode = false) => { /** @type {import('@aws-sdk/client-s3').S3ClientConfig} */ let s3ClientOptions = { region: s3.region, + forcePathStyle: Boolean(s3.forcePathStyle) } if (s3.useAccelerateEndpoint) { diff --git a/packages/@uppy/companion/src/standalone/helper.js b/packages/@uppy/companion/src/standalone/helper.js index dbc3ab875..347dec9cd 100644 --- a/packages/@uppy/companion/src/standalone/helper.js +++ b/packages/@uppy/companion/src/standalone/helper.js @@ -133,6 +133,7 @@ const getConfigFromEnv = () => { process.env.COMPANION_AWS_USE_ACCELERATE_ENDPOINT === 'true', expires: parseInt(process.env.COMPANION_AWS_EXPIRES || '800', 10), acl: process.env.COMPANION_AWS_ACL, + forcePathStyle: process.env.COMPANION_AWS_FORCE_PATH_STYLE === 'true', }, server: { host: process.env.COMPANION_DOMAIN,