Fix relative usage of S3 upload API calls

This commit is contained in:
Andrew Kingston 2022-03-07 09:57:03 +00:00
parent 89e4c59e3c
commit 1e2d745001
1 changed files with 55 additions and 50 deletions

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 }
}, },
}) }
}