Last active
January 20, 2020 16:31
-
-
Save pranay1494/eff1c31fa065f75eb7c6c035832ec7ed to your computer and use it in GitHub Desktop.
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
override fun uploadVideo(pathToVideoFile: String) : Observable<ResponseBody>{ | |
val videoFile = File(pathToVideoFile) | |
val videoRequestBody = ProgressEmittingRequestBody(mediaType = "video/*", file = videoFile) | |
val vFile = MultipartBody.Part.createFormData("file", videoFile.name, videoRequestBody) | |
val bodyMap: HashMap<String, @JvmSuppressWildcards RequestBody> = HashMap() | |
val body = responseEntity.multipartRequest.body | |
createRequestBodyMap(bodyMap, body) | |
val amazonUrl = responseEntity.multipartRequest.url | |
val response = uploadApi.uploadVideoToServer(amazonUrl, bodyMap, vFile) | |
return response.observeOn(postExecutionThread.scheduler).subscribeOn(backgroundThreadScheduler.scheduler) | |
} | |
private fun createRequestBodyMap(bodyMap: java.util.HashMap<String, RequestBody>, body: java.util.HashMap<String, String>) { | |
for ((k,v) in body){ | |
bodyMap.put(k,createRequestBody(v)) | |
} | |
} | |
private fun createRequestBody(value: String): RequestBody { | |
return RequestBody.create(MediaType.parse(MULTIPART_FORM_DATA), value) | |
} | |
companion object{ | |
const val MULTIPART_FORM_DATA = "multipart/form-data" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment