Skip to content

Commit

Permalink
@uppy/companion: add s3.forcePathStyle option (#5066)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine du Hamel <[email protected]>
  • Loading branch information
nadeemc and aduh95 authored Jul 2, 2024
1 parent 3921168 commit 7c174e8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/companion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/aws-companion/server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/aws-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions examples/digitalocean-spaces/server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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")')
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/env_example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/src/server/s3-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/companion/src/standalone/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7c174e8

Please sign in to comment.