Package-level declarations
File uploader.
File Uploader
The uploader is used to upload files.
Uploader Configuration.
With configuration you can:
Manage upload parameters
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 = newConfigurationManage 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 = newConfigurationNetwork 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 = newConfigurationMonitor 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
A set of factors representing the state of the uploader and the reasons why the upload might be stopped.
An interface to implement an adapter that translates the uploading state into a notification. The uploader uses it to display notifications during boot.