Automation Update/Create row attachment: stored key loses the dot before the extension (`uuidpdf`), file served without Content-Type
Checklist
- I have searched Budibase discussions and GitHub issues to check if my issue already exists
Hosting
- Method: docker compose
- Budibase version: v3.45.0-cloud.3
Describe the bug
When the Update row (or Create row) automation step saves an attachment from a url + filename, the object stored in the object store has a key with no dot before the extension, e.g.:
app_xxx/attachments/46e0c8e2-f215-43ff-93fe-9e8202f5d896pdfinstead of ...d896.pdf. Because the key has no recognizable extension, the object is uploaded without a Content-Type, and the signed URL is then served as a generic binary file. As a result:
- a PDF embedded in an
<iframe src="{{ row.Devis.url }}">is not displayed and the browser downloads the file instead, - the downloaded file is named
...d896pdf(no extension), - the same file uploaded manually through the attachment field works correctly (key ends with
.pdf,Content-Type: application/pdf).
To Reproduce
- Create a table with an attachment field (e.g.
Devis). - Create an automation that gets a PDF from a REST query (or any file URL) and passes it to an Update row step, with the attachment set to:
url: the file URL (in my case a signed temp URL from a REST query returning a PDF,/files/signed/tmp-file-attachments/...pdf)filename:devis.pdf
- Run the automation.
- Inspect the stored value of the attachment field:
nameisdevis.pdf, butkeyends withpdf(no dot). - Open
row.Devis.urlin the browser or in an iframe: the file is downloaded instead of previewed, with a name lacking.pdf.
Expected behaviour
The key should be <uuid>.pdf (like in the manual upload flow), the object should be stored with Content-Type: application/pdf, and the PDF should be displayable inline.
Root cause (checked on master, commit 14cc763)
In packages/server/src/automations/automationUtils.ts, generateAttachmentRow:
let extension = path.extname(filename)
if (extension.startsWith(".")) {
extension = extension.substring(1, extension.length) // "pdf"
}
...
async function uploadToS3(extension: string, content: objectStore.StreamTypes) {
const fileName = `${uuid.v4()}${extension}` // "<uuid>pdf" <- dot is missing
const s3Key = `${prodAppId}/attachments/${fileName}`
await objectStore.streamUpload({
bucket: objectStore.ObjectStoreBuckets.APPS,
stream: content,
filename: s3Key, // no `type` passed
})
...
}streamUpload then resolves the content type from the key (resolveContentType in packages/backend-core/src/objectStore/objectStore.ts uses filename.split(".").pop()). With a key that contains no dot, the lookup in CONTENT_TYPE_MAP returns undefined, so no ContentType is set on the object.
By comparison, the regular upload endpoint (uploadFile in packages/server/src/api/controllers/static/index.ts) builds the key with the dot (`${uuid.v4()}.${extension}`) and also passes type: rawMimeType to objectStore.upload.
Suggested fix
- Keep the dot when building the key in
uploadToS3(e.g.`${uuid.v4()}.${extension}`, handling the case of an empty extension), and/or - Pass an explicit
typetostreamUpload(for example theContent-Typeof the fetched response, or a lookup from the extension), so that the object always has a proper content type.
Workaround
Only server-side: force Content-Type: application/pdf on the reverse proxy for signed URLs ending with pdf. There is no workaround from the automation itself, since the extension of filename cannot contain a dot after path.extname + substring(1).
Source: Budibase/budibase