1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

MPPFile#asMultipartFile

This commit is contained in:
InsanusMokrassar 2021-09-08 20:58:44 +06:00
parent 5d6ba0f59e
commit 807952201b
4 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,7 @@
* `Core`:
* `MultipartRequestCallFactory` now will use file name as multipart `filename` parameter instead of generated
filename
* New extension `MPPFile#asMultipartFile`
## 0.35.7

View File

@ -1,7 +1,9 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.micro_utils.common.MPPFile
import dev.inmo.tgbotapi.utils.*
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.Input
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.*
@ -75,3 +77,5 @@ suspend inline fun ByteReadChannel.asMultipartFile(
suspend inline fun ByteReadChannelAllocator.asMultipartFile(
fileName: String
) = this.invoke().asMultipartFile(fileName)
expect suspend fun MPPFile.asMultipartFile(): MultipartFile

View File

@ -0,0 +1,8 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.micro_utils.common.*
import io.ktor.utils.io.ByteReadChannel
actual suspend fun MPPFile.asMultipartFile(): MultipartFile = ByteReadChannel(bytes()).asMultipartFile(
filename.name
)

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.micro_utils.common.MPPFile
actual suspend fun MPPFile.asMultipartFile(): MultipartFile = toInputFile()