Merge pull request #4817 from Budibase/fix/s3-upload
Fix S3 upload component
This commit is contained in:
commit
5928e9326d
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,61 +1,66 @@
|
||||||
export const buildAttachmentEndpoints = API => ({
|
export const buildAttachmentEndpoints = API => {
|
||||||
/**
|
|
||||||
* Uploads an attachment to the server.
|
|
||||||
* @param data the attachment to upload
|
|
||||||
* @param tableId the table ID to upload to
|
|
||||||
*/
|
|
||||||
uploadAttachment: async ({ data, tableId }) => {
|
|
||||||
return await API.post({
|
|
||||||
url: `/api/attachments/${tableId}/upload`,
|
|
||||||
body: data,
|
|
||||||
json: false,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uploads an attachment to the server as a builder user from the builder.
|
|
||||||
* @param data the data to upload
|
|
||||||
*/
|
|
||||||
uploadBuilderAttachment: async data => {
|
|
||||||
return await API.post({
|
|
||||||
url: "/api/attachments/process",
|
|
||||||
body: data,
|
|
||||||
json: false,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a signed URL to upload a file to an external datasource.
|
* Generates a signed URL to upload 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
|
||||||
* @param bucket the name of the bucket to upload to
|
* @param bucket the name of the bucket to upload to
|
||||||
* @param key the name of the file to upload to
|
* @param key the name of the file to upload to
|
||||||
*/
|
*/
|
||||||
getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => {
|
const getSignedDatasourceURL = async ({ datasourceId, bucket, key }) => {
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/attachments/${datasourceId}/url`,
|
url: `/api/attachments/${datasourceId}/url`,
|
||||||
body: { bucket, key },
|
body: { bucket, key },
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
return {
|
||||||
* Uploads a file to an external datasource.
|
getSignedDatasourceURL,
|
||||||
* @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
|
* Uploads an attachment to the server.
|
||||||
* @param data the file to upload
|
* @param data the attachment to upload
|
||||||
*/
|
* @param tableId the table ID to upload to
|
||||||
externalUpload: async ({ datasourceId, bucket, key, data }) => {
|
*/
|
||||||
const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({
|
uploadAttachment: async ({ data, tableId }) => {
|
||||||
datasourceId,
|
return await API.post({
|
||||||
bucket,
|
url: `/api/attachments/${tableId}/upload`,
|
||||||
key,
|
body: data,
|
||||||
})
|
json: false,
|
||||||
await API.put({
|
})
|
||||||
url: signedUrl,
|
},
|
||||||
body: data,
|
|
||||||
json: false,
|
/**
|
||||||
external: true,
|
* Uploads an attachment to the server as a builder user from the builder.
|
||||||
})
|
* @param data the data to upload
|
||||||
return { publicUrl }
|
*/
|
||||||
},
|
uploadBuilderAttachment: async data => {
|
||||||
})
|
return await API.post({
|
||||||
|
url: "/api/attachments/process",
|
||||||
|
body: data,
|
||||||
|
json: false,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads 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
|
||||||
|
* @param data the file to upload
|
||||||
|
*/
|
||||||
|
externalUpload: async ({ datasourceId, bucket, key, data }) => {
|
||||||
|
console.log(API)
|
||||||
|
const { signedUrl, publicUrl } = await getSignedDatasourceURL({
|
||||||
|
datasourceId,
|
||||||
|
bucket,
|
||||||
|
key,
|
||||||
|
})
|
||||||
|
await API.put({
|
||||||
|
url: signedUrl,
|
||||||
|
body: data,
|
||||||
|
json: false,
|
||||||
|
external: true,
|
||||||
|
})
|
||||||
|
return { publicUrl }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue