Created
February 25, 2020 20:21
-
-
Save lordcodes/aa95d7944ac0fca64910daf037c8e73b to your computer and use it in GitHub Desktop.
Code for the article: "Uploading a file with progress in Kotlin"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun uploadAttachment( | |
filename: String, file: File, mimeType: String | |
): Observable<AttachmentUploadRemoteResult> { | |
val progressEmitter = PublishSubject.create<Double>() | |
val uploadRequest = createUploadRequest( | |
filename, file, mimeType, progressEmitter | |
) | |
val uploadResult = uploadRequest | |
.map<AttachmentUploadRemoteResult> { | |
CountingRequestResult.Completed(it.result) | |
} | |
.toObservable() | |
val progressResult = progressEmitter | |
.map<AttachmentUploadRemoteResult> { | |
CountingRequestResult.Progress(it) | |
} | |
return progressResult.mergeWith(uploadResult) | |
} | |
typealias AttachmentUploadRemoteResult = | |
CountingRequestResult<AttachmentUploadedRemoteDto> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment