I'm trying to post to a website using MultiPartFor...
# ktor
j
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
Seems correct, although in the spec I see only field with the name
file
but you append
file1
,
file2
, etc.