Package-level declarations

File uploader.

File Uploader

The uploader is used to upload files.

Uploader Configuration.

With configuration you can:

  1. Manage upload parameters

  2. Configure network policy

The following code example demonstrates changing the uploader configuration.

val fileManager: FileManager
val uploader: FileUploader = fileManager.uploader
val newConfiguration: UploaderConfiguration = uploader.configuration.copy(
isCellularUploadEnabled = true,
maxRetryCount = 2
)

uploader.configuration = newConfiguration

Manage Upload

Upload configuration includes four parameters. As shown in the following example.

val fileManager: FileManager
val uploader: Uploader = fileManager.uploader

val newConfiguration: UploaderConfiguration = uploader.configuration.copy(

// Number of retries to upload a media file. Default - 3.
maxRetryCount = 1
)

uploader.configuration = newConfiguration

Network configuration

Network configuration includes three parameters. As shown in the following example.

val fileManager: FileManager
val uploader: FileUploader = fileManager.uploader
val newConfiguration: UploaderConfiguration = uploader.configuration.copy(

// If true - upload allowed when using cellular network. Default - false.
isCellularUploadEnabled = true,

// If true - upload allowed in roaming (using cellular network). Default - false.
isRoamingUploadEnabled = true
)

uploader.configuration = newConfiguration

Monitor Upload Status

The status of the uploader is represented by the UploaderStatus class. Using it, you can get information about the number of files in the upload queue, the number of active workers, a list of factors why the uploader is not active and another upload factors.

The following code example demonstrates monitoring of uploader status.

val uploader: FileUploader

lifecycleScope.launch {
uploader.stateFlow.collect { uploaderStatus ->
// Set of non critical upload factors.
uploaderStatus.nonCriticalFactors

// List of factors why upload is inactive. The uploader is active if the set is empty.
uploaderStatus.criticalFactors

// The number of worker that are currently active.
uploaderStatus.activeWorkerCount

// The number of files that are in the queue for uploading.
uploaderStatus.inQueueFilesCount
}
}

Upload factors are particles that reflect the state of loading in general and the state of loaders in particular. Factors are described by the UploadFactors enum class.

Assign Files To Uploader

With a uploader, you can assign files to upload.

val uploader: Uploader
val mediaIds: List<Long>

lifecycleScope.launch {
uploader.upload(
uris = listOf<Uri>(),
parentFileId = "ID of the file where the files will be placed after it is uploaded.",
withCache = false,
deleteFileAfterComplete = false
)
}

Set Notification Adapter

To add a notification, you can use the following code example.

val uploader: FileUploader
val fileIds: List<String>

val adapter = object : UploadNotificationAdapter {
override fun statusToNotification(inUploadQueueFilesCount: Int): Notification {
// impl...
}
}
uploader.setNotificationAdapter(adapter)

Introduction To Uploader Logging

This section describes logging the main uploader subsystems. The uploader uses the logging prefix "UL". Log example.

UploaderController : [Fl] [UL] Started!

An example of a uploader configurator log.

UploaderConfigurator : [Fl] [UL] Configuration changed!
cellular - false | max retry count - 3
roaming - false |

An example of a uploader worker log.

UploaderWorker	: [Fl] [UL] [Worker - 4] [id - `7`] Upload result - ...

Types

Link copied to clipboard
interface FileUploader
Link copied to clipboard
data class UploaderConfiguration(val isCellularUploadEnabled: Boolean, val isRoamingUploadEnabled: Boolean, val maxRetryCount: Int) : Parcelable
Link copied to clipboard
data class UploaderStatus(val nonCriticalFactors: Set<UploadFactor>, val criticalFactors: Set<UploadFactor>, val activeWorkerCount: Int, val inQueueFilesCount: Int)
Link copied to clipboard

A set of factors representing the state of the uploader and the reasons why the upload might be stopped.

Link copied to clipboard
class UploadLimitExceededException(message: String, val isUriQuotaExceeded: Boolean) : IOException
Link copied to clipboard

An interface to implement an adapter that translates the uploading state into a notification. The uploader uses it to display notifications during boot.

Link copied to clipboard