rudolf.hladik
08/21/2024, 10:33 AMrudolf.hladik
08/21/2024, 10:35 AMval formData = formData {
append("file", data, headers)
}
val multipart = MultiPartFormDataContent(formData)
val response = httpClient
.post(url) {
setBody(multipart)
}
and it looks like this from logger
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 7697
-> Content-Type: multipart/form-data; boundary=78282c352c930955-90680557dab423d-6be60bfd-4b7e92bb-5b9073585afbc3f251c
BODY Content-Type: multipart/form-data; boundary=78282c352c930955-90680557dab423d-6be60bfd-4b7e92bb-5b9073585afbc3f251c
BODY START
[request body omitted]
BODY END
and I need to be like this in postmanrudolf.hladik
08/21/2024, 10:37 AMfile
is present in request bodyrudolf.hladik
08/21/2024, 10:52 AMRequired part 'file' is not present.
which is exactly the same as if I omit the key in postmanrudolf.hladik
08/21/2024, 10:52 AMAleksei Tirman [JB]
08/21/2024, 12:39 PMrudolf.hladik
08/21/2024, 12:41 PMContent-Disposition
with "name=\"file\""
rudolf.hladik
08/21/2024, 12:41 PMfilename
rudolf.hladik
08/21/2024, 1:09 PMREQUEST: https://...
METHOD: HttpMethod(value=POST)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 7721
-> Content-Type: multipart/form-data; boundary=-1ceef7fe259f1c04-56c9a7c81859744-56e52e78-ebfe80f-24b311ef-72e3f49547
BODY Content-Type: multipart/form-data; boundary=-1ceef7fe259f1c04-56c9a7c81859744-56e52e78-ebfe80f-24b311ef-72e3f49547
BODY START
[request body omitted]
BODY END
rudolf.hladik
08/21/2024, 1:16 PMcurl -X POST "<http://localhost:8080/api/files/upload>" \
-H "Content-Type: multipart/form-data" \
-F "file=@/Users/username/Documents/myfile.txt"
but can't figure out how to include the key file
rudolf.hladik
08/21/2024, 2:38 PMAleksei Tirman [JB]
08/21/2024, 2:38 PMclient.post("<http://localhost:8080/api/files/upload>") {
setBody(MultiPartFormDataContent(
formData {
append("file", File("/Users/username/Documents/myfile.txt").readBytes(), Headers.build {
append(HttpHeaders.ContentType, "text/plain")
append(HttpHeaders.ContentDisposition, "filename=\"myfile.txt\"")
})
}
))
}
rudolf.hladik
08/21/2024, 6:22 PM