Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
object FileUploader {
const val QUEUE_NAME = "YOUR_NAME"
fun submitFileUploadWork(newMessage: NewMessage, uploadUrl: String) {
val data = Data.Builder()
.putString(NewMessage.KEY_JOB_ID, newMessage.jobId)
.putString(NewMessage.KEY_FILE_PATH, newMessage.mediaFile.absolutePath)
.putString(NewMessage.KEY_UPLOAD_URL, uploadUrl)
.build()
val work = OneTimeWorkRequest.Builder(FileUploadWorker::class.java)
.setInputData(data)
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
.build()
val workerManager = WorkManager.getInstance()
val workContinuation = workerManager.beginUniqueWork(
QUEUE_NAME,
ExistingWorkPolicy.APPEND,
work
)
workContinuation.enqueue()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.