Merge branch 'browser-compat' of github.com:Budibase/budibase into browser-compat

This commit is contained in:
mike12345567 2021-03-16 14:12:26 +00:00
commit 7c5771c32d
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,