@uppy/companion: add s3.forcePathStyle option (#5066)

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Nadeem Reinhardt 2024-07-02 07:13:35 -07:00 committed by GitHub
parent 392116898c
commit 7c174e85b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 15 additions and 0 deletions

View file

@ -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

View file

@ -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 clients `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.

View file

@ -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,

View file

@ -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
}

View file

@ -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,

View file

@ -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=

View file

@ -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) {

View file

@ -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,