From c0cf70720a41a2a53a2e8407dc94eaf25a1ee26b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 16 Mar 2021 13:51:50 +0000 Subject: [PATCH] Revert deletion of S3 upload of attachments in cloud env --- .../src/api/controllers/static/index.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index f5de271d36..ff1ecf5b2e 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -5,6 +5,8 @@ const { resolve, join } = require("../../../utilities/centralPath") const fetch = require("node-fetch") const fs = require("fs-extra") const uuid = require("uuid") +const AWS = require("aws-sdk") +const { prepareUpload } = require("../deploy/utils") const { processString } = require("@budibase/string-templates") const { budibaseAppsDir, @@ -72,6 +74,29 @@ exports.uploadFile = async function(ctx) { "attachments" ) + if (env.CLOUD) { + // remote upload + const s3 = new AWS.S3({ + params: { + Bucket: "prod-budi-app-assets", + }, + }) + + const uploads = files.map(file => { + const fileExtension = [...file.name.split(".")].pop() + const processedFileName = `${uuid.v4()}.${fileExtension}` + + return prepareUpload({ + file, + s3Key: `assets/${ctx.user.appId}/attachments/${processedFileName}`, + s3, + }) + }) + + ctx.body = await Promise.all(uploads) + return + } + ctx.body = await processLocalFileUploads({ files, outputPath: attachmentsPath,