DownloadFileToDisk

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

Downloads url into the client's own file storage under targetFileName, where GetFile and DeleteFiles can reach it afterwards. 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 — unless it failed for lack of device storage, in which case only onInsufficientDiskSpace fires (carrying the Throwable, logged) and the partially written file is deleted.

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, onInsufficientDiskSpace).

url

URL to download.

method

HTTP method used for the request, built with httpGet, httpPost, httpPut, httpDelete, httpPatch etc.

body

Request body. Defaults to none.

headers

Request headers. Defaults to none.

targetFileName

Name the downloaded file is saved under, in the client's own storage.

timeouts

Request, connect and socket timeout overrides, built with timeout. Defaults to none (client defaults).