From f0d31ed27aa6d85265571590751dd89cebb2d8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl?= Date: Wed, 3 Apr 2024 09:32:45 -0400 Subject: [PATCH] Add support for file uploads with custom S3 endpoints Addresses #5459 --- .github/AUTHORS.md | 3 ++- .../settings/controls/S3DataSourceSelect.svelte | 2 +- .../server/src/api/controllers/static/index.ts | 14 ++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/AUTHORS.md b/.github/AUTHORS.md index df346f3325..d31bb64987 100644 --- a/.github/AUTHORS.md +++ b/.github/AUTHORS.md @@ -8,4 +8,5 @@ Contributors * Andrew Kingston - [@aptkingston](https://github.com/aptkingston) * Michael Drury - [@mike12345567](https://github.com/mike12345567) * Peter Clement - [@PClmnt](https://github.com/PClmnt) -* Rory Powell - [@Rory-Powell](https://github.com/Rory-Powell) \ No newline at end of file +* Rory Powell - [@Rory-Powell](https://github.com/Rory-Powell) +* Michaƫl St-Georges [@CSLTech](https://github.com/CSLTech) \ No newline at end of file diff --git a/packages/builder/src/components/design/settings/controls/S3DataSourceSelect.svelte b/packages/builder/src/components/design/settings/controls/S3DataSourceSelect.svelte index d5d42f1514..c52532508c 100644 --- a/packages/builder/src/components/design/settings/controls/S3DataSourceSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/S3DataSourceSelect.svelte @@ -5,7 +5,7 @@ export let value = null $: dataSources = $datasources.list - .filter(ds => ds.source === "S3" && !ds.config?.endpoint) + .filter(ds => ds.source === "S3") .map(ds => ({ label: ds.name, value: ds._id, diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index f004921d08..dfaec2ab36 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -300,11 +300,6 @@ export const getSignedUploadURL = async function (ctx: Ctx) { ctx.throw(400, "The specified datasource could not be found") } - // Ensure we aren't using a custom endpoint - if (datasource?.config?.endpoint) { - ctx.throw(400, "S3 datasources with custom endpoints are not supported") - } - // Determine type of datasource and generate signed URL let signedUrl let publicUrl @@ -317,6 +312,7 @@ export const getSignedUploadURL = async function (ctx: Ctx) { try { const s3 = new AWS.S3({ region: awsRegion, + endpoint: datasource?.config?.endpoint as string, accessKeyId: datasource?.config?.accessKeyId as string, secretAccessKey: datasource?.config?.secretAccessKey as string, apiVersion: "2006-03-01", @@ -324,7 +320,13 @@ export const getSignedUploadURL = async function (ctx: Ctx) { }) const params = { Bucket: bucket, Key: key } signedUrl = s3.getSignedUrl("putObject", params) - publicUrl = `https://${bucket}.s3.${awsRegion}.amazonaws.com/${key}` + if (datasource?.config?.endpoint) { + publicUrl = `${datasource.config.endpoint}/${bucket}/${key}` + } + else { + publicUrl = `https://${bucket}.s3.${awsRegion}.amazonaws.com/${key}` + } + } catch (error: any) { ctx.throw(400, error) }