1
0
Fork 0
mirror of synced 2024-07-08 15:56:23 +12:00

Merge pull request #4817 from Budibase/fix/s3-upload

Fix S3 upload component
This commit is contained in:
Andrew Kingston 2022-03-08 08:42:18 +00:00 committed by GitHub
commit 5928e9326d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2748 additions and 51 deletions

View file

@ -81,7 +81,10 @@
loading = false loading = false
return res return res
} catch (error) { } catch (error) {
notificationStore.actions.error(`Error uploading file: ${error}`) notificationStore.actions.error(
`Error uploading file: ${error?.message || error}`
)
loading = false
} }
} }

2689
packages/client/stats.html Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,20 @@
export const buildAttachmentEndpoints = API => ({ export const buildAttachmentEndpoints = API => {
/**
* Generates a signed URL to upload a file to an external datasource.
* @param datasourceId the ID of the datasource to upload to
* @param bucket the name of the bucket to upload to
* @param key the name of the file to upload to
*/
const getSignedDatasourceURL = async ({ datasourceId, bucket, key }) => {
return await API.post({
url: `/api/attachments/${datasourceId}/url`,
body: { bucket, key },
})
}
return {
getSignedDatasourceURL,
/** /**
* Uploads an attachment to the server. * Uploads an attachment to the server.
* @param data the attachment to upload * @param data the attachment to upload
@ -24,19 +40,6 @@ export const buildAttachmentEndpoints = API => ({
}) })
}, },
/**
* Generates a signed URL to upload a file to an external datasource.
* @param datasourceId the ID of the datasource to upload to
* @param bucket the name of the bucket to upload to
* @param key the name of the file to upload to
*/
getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => {
return await API.post({
url: `/api/attachments/${datasourceId}/url`,
body: { bucket, key },
})
},
/** /**
* Uploads a file to an external datasource. * Uploads a file to an external datasource.
* @param datasourceId the ID of the datasource to upload to * @param datasourceId the ID of the datasource to upload to
@ -45,7 +48,8 @@ export const buildAttachmentEndpoints = API => ({
* @param data the file to upload * @param data the file to upload
*/ */
externalUpload: async ({ datasourceId, bucket, key, data }) => { externalUpload: async ({ datasourceId, bucket, key, data }) => {
const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({ console.log(API)
const { signedUrl, publicUrl } = await getSignedDatasourceURL({
datasourceId, datasourceId,
bucket, bucket,
key, key,
@ -58,4 +62,5 @@ export const buildAttachmentEndpoints = API => ({
}) })
return { publicUrl } return { publicUrl }
}, },
}) }
}