Merge pull request #13395 from CSLTech/5459_S3EndpointSupport

Add support for file uploads with custom S3 endpoints
This commit is contained in:
Martin McKeaveney 2024-05-15 14:53:23 +01:00 committed by GitHub
commit a46e109ca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

1
.github/AUTHORS.md vendored
View File

@ -9,3 +9,4 @@ Contributors
* Michael Drury - [@mike12345567](https://github.com/mike12345567) * Michael Drury - [@mike12345567](https://github.com/mike12345567)
* Peter Clement - [@PClmnt](https://github.com/PClmnt) * Peter Clement - [@PClmnt](https://github.com/PClmnt)
* Rory Powell - [@Rory-Powell](https://github.com/Rory-Powell) * Rory Powell - [@Rory-Powell](https://github.com/Rory-Powell)
* Michaël St-Georges [@CSLTech](https://github.com/CSLTech)

View File

@ -5,7 +5,7 @@
export let value = null export let value = null
$: dataSources = $datasources.list $: dataSources = $datasources.list
.filter(ds => ds.source === "S3" && !ds.config?.endpoint) .filter(ds => ds.source === "S3")
.map(ds => ({ .map(ds => ({
label: ds.name, label: ds.name,
value: ds._id, value: ds._id,

View File

@ -292,11 +292,6 @@ export const getSignedUploadURL = async function (ctx: Ctx) {
ctx.throw(400, "The specified datasource could not be found") 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 // Determine type of datasource and generate signed URL
let signedUrl let signedUrl
let publicUrl let publicUrl
@ -309,6 +304,7 @@ export const getSignedUploadURL = async function (ctx: Ctx) {
try { try {
const s3 = new AWS.S3({ const s3 = new AWS.S3({
region: awsRegion, region: awsRegion,
endpoint: datasource?.config?.endpoint as string,
accessKeyId: datasource?.config?.accessKeyId as string, accessKeyId: datasource?.config?.accessKeyId as string,
secretAccessKey: datasource?.config?.secretAccessKey as string, secretAccessKey: datasource?.config?.secretAccessKey as string,
apiVersion: "2006-03-01", apiVersion: "2006-03-01",
@ -316,7 +312,13 @@ export const getSignedUploadURL = async function (ctx: Ctx) {
}) })
const params = { Bucket: bucket, Key: key } const params = { Bucket: bucket, Key: key }
signedUrl = s3.getSignedUrl("putObject", params) 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) { } catch (error: any) {
ctx.throw(400, error) ctx.throw(400, error)
} }