Browse Source

No default aws region

master
Mel O'Hagan 4 years ago
parent
commit
b0a3abc308
  1. 9
      packages/server/src/api/controllers/static/index.js

9
packages/server/src/api/controllers/static/index.js

@ -114,10 +114,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 AWS_REGION = const awsRegion = datasource?.config?.region
datasource?.config?.region?.length > 0
? 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) {
@ -126,7 +123,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",
@ -134,7 +131,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)
} }

Loading…
Cancel
Save