Merge pull request #6335 from Budibase/bug/sev3/cors-error-non-eu-s3
Use s3 region from datasource config
This commit is contained in:
commit
a5f4de9d7d
|
@ -17,7 +17,6 @@ const { attachmentsRelativeURL } = require("../../../utilities")
|
||||||
const { DocumentTypes, isDevAppID } = require("../../../db/utils")
|
const { DocumentTypes, isDevAppID } = require("../../../db/utils")
|
||||||
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
||||||
const AWS = require("aws-sdk")
|
const AWS = require("aws-sdk")
|
||||||
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
|
|
||||||
const { events } = require("@budibase/backend-core")
|
const { events } = require("@budibase/backend-core")
|
||||||
|
|
||||||
async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
async function prepareUpload({ s3Key, bucket, metadata, file }) {
|
||||||
|
@ -130,6 +129,7 @@ exports.getSignedUploadURL = async function (ctx) {
|
||||||
// Determine type of datasource and generate signed URL
|
// Determine type of datasource and generate signed URL
|
||||||
let signedUrl
|
let signedUrl
|
||||||
let publicUrl
|
let publicUrl
|
||||||
|
const awsRegion = datasource?.config?.region || "eu-west-1"
|
||||||
if (datasource.source === "S3") {
|
if (datasource.source === "S3") {
|
||||||
const { bucket, key } = ctx.request.body || {}
|
const { bucket, key } = ctx.request.body || {}
|
||||||
if (!bucket || !key) {
|
if (!bucket || !key) {
|
||||||
|
@ -138,7 +138,7 @@ exports.getSignedUploadURL = async function (ctx) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const s3 = new AWS.S3({
|
const s3 = new AWS.S3({
|
||||||
region: AWS_REGION,
|
region: awsRegion,
|
||||||
accessKeyId: datasource?.config?.accessKeyId,
|
accessKeyId: datasource?.config?.accessKeyId,
|
||||||
secretAccessKey: datasource?.config?.secretAccessKey,
|
secretAccessKey: datasource?.config?.secretAccessKey,
|
||||||
apiVersion: "2006-03-01",
|
apiVersion: "2006-03-01",
|
||||||
|
@ -146,7 +146,7 @@ exports.getSignedUploadURL = async function (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.${AWS_REGION}.amazonaws.com/${key}`
|
publicUrl = `https://${bucket}.s3.${awsRegion}.amazonaws.com/${key}`
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ctx.throw(400, error)
|
ctx.throw(400, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ const clearMigrations = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jest.setTimeout(10000)
|
||||||
|
|
||||||
describe("migrations", () => {
|
describe("migrations", () => {
|
||||||
const config = new TestConfig()
|
const config = new TestConfig()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue