Revert deletion of S3 upload of attachments in cloud env

This commit is contained in:
Andrew Kingston 2021-03-16 13:51:50 +00:00
parent 05b6e825b4
commit 9212a2f623
1 changed files with 25 additions and 0 deletions

View File

@ -5,6 +5,8 @@ const { resolve, join } = require("../../../utilities/centralPath")
const fetch = require("node-fetch") const fetch = require("node-fetch")
const fs = require("fs-extra") const fs = require("fs-extra")
const uuid = require("uuid") const uuid = require("uuid")
const AWS = require("aws-sdk")
const { prepareUpload } = require("../deploy/utils")
const { processString } = require("@budibase/string-templates") const { processString } = require("@budibase/string-templates")
const { const {
budibaseAppsDir, budibaseAppsDir,
@ -72,6 +74,29 @@ exports.uploadFile = async function(ctx) {
"attachments" "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({ ctx.body = await processLocalFileUploads({
files, files,
outputPath: attachmentsPath, outputPath: attachmentsPath,