FileDownloadTask

Downloads a file from a URL to a destination file.

A FileDownloadTask supports:

  • Starting the download by calling start.

  • Pausing and resuming the download if the server supports it. Call pause to pause a download and start to resume it. If pausing is not supported, canPause will always emit false. If pausing is supported, canPause will emit true after the download has started.

  • Cancelling the download by calling cancel.

  • Progress updates if the server supports it, by emitting ProgressInfo in the progress state flow. If progress is not supported by the server, ProgressInfo.totalBytes will always return null.

  • Download status is provided in the status state flow.

The download must be initiated by calling start, and client code can suspend until the download has completed by calling result.

Example:

val downloadTask = ArcGISEnvironment.arcGISHttpClient.downloadWithTask(url, destination)
downloadTask.start()
downloadTask.result().onSuccess {
// use file...
}.onFailure { error ->
// handle download error...
}

Since

200.6.0

Types

Link copied to clipboard
data class ProgressInfo

Represents the progress of the download.

Link copied to clipboard
sealed class Status

Represents the status of the download.

Properties

Link copied to clipboard
val canPause: StateFlow<Boolean>

Indicates if the download can be paused. The download can be paused if the server supports range requests. The flow may emit true after the download has started.

Link copied to clipboard
Link copied to clipboard

The current progress of the download.

Link copied to clipboard

The current status of the download.

Link copied to clipboard
val url: String

Functions

Link copied to clipboard

Cancels the download. Successful cancellation will result in a Status.Failed status with an IOException.

Link copied to clipboard
fun pause(): Boolean

Pauses the download if the server supports it.

Link copied to clipboard
suspend fun result(): Result<Unit>

Suspends until the download has completed.

Link copied to clipboard
fun start(): Boolean

Starts the download. To suspend until the download has completed, call result after calling this function.