birb-integrated-bench/src/Uploader.kt

41 lines
1.4 KiB
Kotlin
Raw Normal View History

2020-10-22 02:11:14 +02:00
package com.kmlabz.k8s
import com.google.gson.Gson
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.client.request.*
import io.ktor.client.request.forms.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.util.*
class Uploader(){
@KtorExperimentalAPI
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
HttpClient(Apache).use { client ->
val parts: List<PartData> = formData {
val headersBuilder = HeadersBuilder()
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
headersBuilder[HttpHeaders.ContentDisposition] = "filename=csirip.wav"
this.append(
"file",
inputSound,
headersBuilder.build()
)
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", currIteration)
val jsonHeadersBuilder = HeadersBuilder()
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
this.append(
"description",
gson.toJson(inputSvcApi),
jsonHeadersBuilder.build()
)
}
client.submitFormWithBinaryData<Unit>(formData = parts) {
2020-10-22 02:24:36 +02:00
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
2020-10-22 02:11:14 +02:00
}
}
}
}