Created
February 4, 2021 10:28
-
-
Save raghunandankavi2010/0a80d7f63ada60853e471f2e62004d27 to your computer and use it in GitHub Desktop.
InputStreamRequestBody for retrofit
This file contains hidden or 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
import okhttp3.MediaType | |
import okhttp3.RequestBody | |
import okio.BufferedSink | |
import okio.source | |
import java.io.IOException | |
import java.io.InputStream | |
class InputStreamRequestBody(private val contentType: MediaType, private val inputStream: InputStream) : RequestBody() { | |
override fun contentType(): MediaType { | |
return contentType | |
} | |
@Throws(IOException::class) | |
override fun contentLength(): Long { | |
return -1 | |
} | |
@Throws(IOException::class) | |
override fun writeTo(sink: BufferedSink) { | |
sink.writeAll(inputStream.source()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
val file = InputStreamRequestBody("multipart/form-data".toMediaType(),inputStream)