From b3dba52d629946619b4c5d0ace134674a34193c5 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 13 Jan 2022 17:18:24 +0000 Subject: [PATCH] Update S3 upload with develop and fix preview URLs --- packages/bbui/src/Form/Core/Dropzone.svelte | 7 +- packages/client/src/api/attachments.js | 20 ++++- .../src/components/app/forms/S3Upload.svelte | 80 +++++++++++++++---- .../src/api/controllers/static/index.js | 38 +++++++++ packages/server/src/api/routes/datasource.js | 5 -- packages/server/src/api/routes/static.js | 6 ++ 6 files changed, 134 insertions(+), 22 deletions(-) diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index bbaf5a3ff9..01b63be1bc 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -146,7 +146,9 @@ preview {:else}
-
{selectedImage.extension}
+
+ {selectedImage.name || "Unknown file"} +
Preview not supported
{/if} @@ -357,18 +359,21 @@ white-space: nowrap; width: 0; margin-right: 10px; + user-select: all; } .placeholder { display: flex; flex-direction: column; justify-content: center; align-items: center; + text-align: center; } .extension { color: var(--spectrum-global-color-gray-600); text-transform: uppercase; font-weight: 600; margin-bottom: 5px; + user-select: all; } .nav { diff --git a/packages/client/src/api/attachments.js b/packages/client/src/api/attachments.js index 9bb5aa0a49..6e97bbd956 100644 --- a/packages/client/src/api/attachments.js +++ b/packages/client/src/api/attachments.js @@ -11,7 +11,25 @@ export const uploadAttachment = async (data, tableId = "") => { }) } -export const uploadToS3 = async (signedUrl, data) => { +/** + * Generates a signed URL to upload a file to an external datasource. + */ +export const getSignedDatasourceURL = async (datasourceId, bucket, key) => { + if (!datasourceId) { + return null + } + const res = await API.post({ + url: `/api/attachments/${datasourceId}/url`, + body: { bucket, key }, + }) + return res?.signedUrl +} + +/** + * Uploads a file to an external datasource. + */ +export const externalUpload = async (datasourceId, bucket, key, data) => { + const signedUrl = await getSignedDatasourceURL(datasourceId, bucket, key) await API.put({ url: signedUrl, body: data, diff --git a/packages/client/src/components/app/forms/S3Upload.svelte b/packages/client/src/components/app/forms/S3Upload.svelte index 1f2d308e66..62f154657e 100644 --- a/packages/client/src/components/app/forms/S3Upload.svelte +++ b/packages/client/src/components/app/forms/S3Upload.svelte @@ -1,8 +1,7 @@