diff --git a/packages/client/src/api/attachments.js b/packages/client/src/api/attachments.js index 6e97bbd956..fdc47636c0 100644 --- a/packages/client/src/api/attachments.js +++ b/packages/client/src/api/attachments.js @@ -1,4 +1,5 @@ import API from "./api" +import { notificationStore } from "../stores/index.js" /** * Uploads an attachment to the server. @@ -22,6 +23,9 @@ export const getSignedDatasourceURL = async (datasourceId, bucket, key) => { url: `/api/attachments/${datasourceId}/url`, body: { bucket, key }, }) + if (res.error) { + throw "Could not generate signed upload URL" + } return res?.signedUrl } @@ -30,10 +34,13 @@ export const getSignedDatasourceURL = async (datasourceId, bucket, key) => { */ export const externalUpload = async (datasourceId, bucket, key, data) => { const signedUrl = await getSignedDatasourceURL(datasourceId, bucket, key) - await API.put({ + const res = await API.put({ url: signedUrl, body: data, json: false, external: true, }) + if (res.error) { + throw "Could not upload file to signed URL" + } } diff --git a/packages/client/src/components/app/forms/S3Upload.svelte b/packages/client/src/components/app/forms/S3Upload.svelte index 62f154657e..8072b92e59 100644 --- a/packages/client/src/components/app/forms/S3Upload.svelte +++ b/packages/client/src/components/app/forms/S3Upload.svelte @@ -70,7 +70,12 @@ const upload = async () => { loading = true - await API.externalUpload(datasourceId, bucket, key, data) + try { + await API.externalUpload(datasourceId, bucket, key, data) + notificationStore.actions.success("File uploaded successfully") + } catch (error) { + notificationStore.actions.error(`Error uploading file: ${error}`) + } loading = false } diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index b285d04f1c..9687ca2280 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -165,7 +165,6 @@ const s3UploadHandler = async action => { return } await uploadStore.actions.processFileUpload(componentId) - notificationStore.actions.success("File uploaded successfully") } const handlerMap = {