Problem
When an attachment is saved via saveFile(), the mediaType is stored in the local attachment record. However, when another device syncs and the watchAttachments callback creates a new QUEUED_DOWNLOAD record, mediaType is never set — only id, filename, state, metaData, and timestamp are populated.
This means attachment.mediaType is always null on devices that download attachments from remote storage, even though the uploading device had the correct MIME type.
Relevant code (in AttachmentQueue)
// When watchAttachments detects a new attachment:
attachmentUpdates.push({
id: watchedAttachment.id,
filename,
state: AttachmentState.QUEUED_DOWNLOAD,
hasSynced: false,
metaData: watchedAttachment.metaData,
timestamp: new Date().getTime()
// ← no mediaType
});
Current WatchedAttachmentItem shape
The items passed to onUpdate() only support:
id
fileExtension
filename
metaData
There's no mediaType field.
Proposal
Add an optional mediaType field to WatchedAttachmentItem:
interface WatchedAttachmentItem {
id: string;
fileExtension?: string;
filename?: string;
metaData?: string;
mediaType?: string; // ← new
}
When present, pass it through to the attachment record created for QUEUED_DOWNLOAD:
attachmentUpdates.push({
id: watchedAttachment.id,
filename,
state: AttachmentState.QUEUED_DOWNLOAD,
hasSynced: false,
metaData: watchedAttachment.metaData,
mediaType: watchedAttachment.mediaType, // ← new
timestamp: new Date().getTime()
});
This would allow users to derive the MIME type from their data model (e.g., from the file extension in the attachment ID, or a dedicated column) and pass it through watchAttachments, so downloaded attachments have the correct mediaType.
Workaround
Currently working around this by inferring MIME type from the file extension embedded in the attachment ID (e.g., uuid.webp → image/webp).
Environment
Problem
When an attachment is saved via
saveFile(), themediaTypeis stored in the local attachment record. However, when another device syncs and thewatchAttachmentscallback creates a newQUEUED_DOWNLOADrecord,mediaTypeis never set — onlyid,filename,state,metaData, andtimestampare populated.This means
attachment.mediaTypeis alwaysnullon devices that download attachments from remote storage, even though the uploading device had the correct MIME type.Relevant code (in
AttachmentQueue)Current
WatchedAttachmentItemshapeThe items passed to
onUpdate()only support:idfileExtensionfilenamemetaDataThere's no
mediaTypefield.Proposal
Add an optional
mediaTypefield toWatchedAttachmentItem:When present, pass it through to the attachment record created for
QUEUED_DOWNLOAD:This would allow users to derive the MIME type from their data model (e.g., from the file extension in the attachment ID, or a dedicated column) and pass it through
watchAttachments, so downloaded attachments have the correctmediaType.Workaround
Currently working around this by inferring MIME type from the file extension embedded in the attachment ID (e.g.,
uuid.webp→image/webp).Environment
@powersync/webv1.37.0