https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jan

09/25/2021, 9:22 PM
I'm trying to post to a website using MultiPartFormData. But it seems that I'm doing something wrong. Code: (see thread) Here are the docs for this request: https://discord.com/developers/docs/resources/channel#create-message-example-request-bodies-multipartformdata
Copy code
MultiPartFormDataContent(
    formData {
        var index = 1
        attachments.forEach {
            this.append(key = "file$index", value = it.bytes, headers = Headers.build {
                append(
                    HttpHeaders.ContentDisposition,
                    "filename=${it.fileName}"
                )
            })
            index++
        }
        this.append("payload_json", buildJsonObject {
            putJsonObject(buildJson().toJsonObject())
        }.toString(), headers = buildHeaders {
            append(HttpHeaders.ContentType, "application/json")
        })
    })
a

Aleksei Tirman [JB]

09/27/2021, 10:03 AM
Seems correct, although in the spec I see only field with the name
file
but you append
file1
,
file2
, etc.
6 Views