This commit is contained in:
@@ -6,39 +6,45 @@ import io.ktor.client.*
|
||||
import io.ktor.client.engine.apache.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.*
|
||||
import io.ktor.util.*
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
class Uploader(){
|
||||
class Uploader(currIteration: Int) {
|
||||
private val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
private val inputSound = File("/app/wave.wav").readBytes()
|
||||
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", 1)
|
||||
val jsonHeadersBuilder = HeadersBuilder()
|
||||
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
||||
this.append(
|
||||
"description",
|
||||
gson.toJson(inputSvcApi),
|
||||
jsonHeadersBuilder.build()
|
||||
)
|
||||
}
|
||||
@KtorExperimentalAPI
|
||||
suspend fun uploadData(currIteration: Int) {
|
||||
HttpClient(Apache).use { client ->
|
||||
|
||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
|
||||
}
|
||||
private lateinit var parts: List<PartData>
|
||||
var respInstant : Instant = Instant.now()
|
||||
var currIteration : Int = 0
|
||||
fun buildRequest() {
|
||||
parts = 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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@KtorExperimentalAPI
|
||||
suspend fun sendRequest() {
|
||||
HttpClient(Apache).post<HttpResponse>(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark") {
|
||||
body = parts
|
||||
}
|
||||
respInstant = Instant.now()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user