I'm trying to implement multipart form to post both JSON and a binary file in a single call. The model looks something like this:
struct TestObject: Decodable {
struct User: Decodable {
let username: String
}
let user: TestObject.User
let file: Data
}
I handle this in the call as follows:
app.post("test") { req async throws in
let multipart = try req.content.decode(TestObject.self)
print(multipart)
return "Multipart posted, thanks!"
}
I then execute a curl call as follows:
curl -X POST \
-F user={"username":"John"} \
-F [email protected] \
localhost:8080/test
The response I get is {"error":true,"reason":"Value at path 'user' was not of type 'MultipartPart'. Expected dictionary but encountered single value."}. Why is that and how can I solve this?