uploadAttachment

suspend fun uploadAttachment(data: ByteArray, filename: String, mimeType: String, preferredKind: FeedbackAttachment.Kind? = null, userToken: String? = null): FeedbackAttachment(source)

Uploads a binary file or screenshot attachment to storage and returns a descriptor ready to be attached to a FeedbackDraft.

  • Image MIME types (e.g., image/png, image/jpeg) are routed to POST /api/v1/uploads/images.

  • All other files (e.g. logs, crashes, text) are routed to POST /api/v1/uploads/r2 object storage.

  • Use preferredKind to explicitly override the destination storage backend.

Accepts HTTP 200 OK and 201 Created responses. If userToken is provided, it is forwarded as the X-User-Token header to associate the upload with the anonymous user identity.

Return

A populated FeedbackAttachment containing the persisted URL and storage key.

Parameters

data

Binary payload to upload.

filename

Display file name including extension (e.g. screenshot.png).

mimeType

MIME content type (e.g. image/png, application/pdf).

preferredKind

Optional explicit FeedbackAttachment.Kind, overriding MIME-based auto-detection.

userToken

Optional stable user token (from UserTokenStore) to attribute the upload.

Throws

if the upload succeeded on the server but the response could not be parsed.

if the file upload is rejected (e.g. exceeded maxAttachmentBytes).

if a network error occurs.

Example:

val screenshotBytes = captureViewAsPngBytes(window.decorView)
val attachment = client.uploadAttachment(
data = screenshotBytes,
filename = "device_screenshot.png",
mimeType = "image/png",
userToken = userToken
)
val draft = baseDraft.copy(attachments = listOf(attachment))
client.submit(draft, userToken)