Skip to content

watchAttachments: support mediaType in WatchedAttachmentItem #922

@gutenye

Description

@gutenye

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.webpimage/webp).

Environment

  • @powersync/web v1.37.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions