ribesg
06/05/2019, 8:27 AMe5l
06/05/2019, 8:28 AMContent-type
if you’re using OutgoingContent
as body.ribesg
06/05/2019, 8:29 AMprivate suspend fun doUploadFile(data: ByteReadChannel, uploadUrl: String, contentType: ContentType): Unit =
http.put(uploadUrl) {
headers.clear() // Remove default headers for this request
contentType(contentType)
body = object : OutgoingContent.WriteChannelContent() {
override suspend fun writeTo(channel: ByteWriteChannel) {
data.copyAndClose(channel)
}
}
}
Caused by: io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly
with this codee5l
06/05/2019, 8:37 AMsuspend fun HttpClient.doUploadFile(
data: ByteReadChannel,
uploadUrl: String,
contentType: ContentType
): Unit = put(uploadUrl) {
body = object : OutgoingContent.WriteChannelContent() {
override val contentType: ContentType? get() = contentType
override suspend fun writeTo(channel: ByteWriteChannel) {
data.copyAndClose(channel)
}
}
}
ribesg
06/05/2019, 8:38 AMOutgoingContent
file and I saw ReadChannelContent
, can I use this code instead? What’s the difference?
body = object : OutgoingContent.ReadChannelContent() {
override fun readFrom() = data
}
(Adding the contentType to that)e5l
06/05/2019, 8:39 AMcontentType
in any OutgoingContent
.ribesg
06/05/2019, 8:40 AMReadChannelContent
or a WriteChannelContent
?e5l
06/05/2019, 8:41 AMReadChannelContent
obliges you to provide generating channel. WriteChannelContent
allows you to write content directly.ribesg
06/05/2019, 8:43 AMByteReadChannel
I use ReadChannelContent
, while if I have something else to write like a simple String
or an InputStream
I could write it directly using WriteChannelContent
, am I understanding that correctly?override val contentType
works, thanks.ByteReadChannel