2022-11-22 03:51:10 +00:00
|
|
|
package dev.inmo.micro_utils.ktor.client
|
|
|
|
|
|
|
|
import dev.inmo.micro_utils.common.FileName
|
2022-11-22 04:36:15 +00:00
|
|
|
import dev.inmo.micro_utils.ktor.common.LambdaInputProvider
|
2022-11-22 03:51:10 +00:00
|
|
|
import io.ktor.client.HttpClient
|
|
|
|
import io.ktor.http.Headers
|
|
|
|
import kotlinx.serialization.DeserializationStrategy
|
|
|
|
import kotlinx.serialization.StringFormat
|
2022-11-22 04:36:15 +00:00
|
|
|
import kotlinx.serialization.json.Json
|
2022-11-22 03:51:10 +00:00
|
|
|
|
|
|
|
data class UniUploadFileInfo(
|
|
|
|
val fileName: FileName,
|
2022-11-22 04:36:15 +00:00
|
|
|
val mimeType: String,
|
|
|
|
val inputAllocator: LambdaInputProvider
|
2022-11-22 03:51:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will execute submitting of multipart data request
|
|
|
|
*
|
|
|
|
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
|
|
|
|
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
|
|
|
|
* in case you wish to pass other source of multipart binary data than regular file
|
|
|
|
*/
|
2022-11-22 07:38:36 +00:00
|
|
|
expect suspend fun <T> HttpClient.uniUpload(
|
2022-11-22 03:51:10 +00:00
|
|
|
url: String,
|
|
|
|
data: Map<String, Any>,
|
|
|
|
resultDeserializer: DeserializationStrategy<T>,
|
2022-11-22 04:36:15 +00:00
|
|
|
headers: Headers = Headers.Empty,
|
2022-11-22 06:57:43 +00:00
|
|
|
stringFormat: StringFormat = Json,
|
|
|
|
onUpload: OnUploadCallback = { _, _ -> }
|
2022-11-22 03:51:10 +00:00
|
|
|
): T?
|