DownloadFile

fun EventSchemaBuilderScope.DownloadFile(id: String = randomId(), trigger: EventTrigger, events: EventSchemaBuilderScope.() -> Unit = {}, url: String, method: HttpMethod, body: AnySerializable? = null, headers: Map<String, String>? = null, targetFileName: String, mimeType: String? = null)

Downloads url and hands the result to the platform's own download destination — the user's Downloads folder or equivalent — under targetFileName, with mimeType describing the content. method, headers and body shape the request. Does not consume incomingData. Dispatches onStart before the download begins; onDownloadProgress repeatedly while downloading (carrying the progress); onDownloadFinish then onSuccess (both carrying targetFileName) when the download completed; onDownloadFailure then onFailure (both carrying the Throwable, logged) when it failed; onCancelled (no data) when the user cancels the download — in that case neither download-failure nor failure fires.

Parameters

id

Unique identifier of this event. Defaults to a random id.

trigger

Trigger that fires this event, built via EventTriggers.

events

Child events chained after this one, wired to its triggers (onStart, onDownloadProgress, onDownloadFinish, onDownloadFailure, onSuccess, onFailure, onCancelled).

url

URL to download.

method

HTTP method used for the request.

body

Request body. Defaults to none.

headers

Request headers. Defaults to none.

targetFileName

Name the downloaded file is saved under, in the platform's download destination.

mimeType

MIME type describing the downloaded content. Defaults to none.