Skip to content

Commit 8722a53

Browse files
committed
Properly handle multipart/form-data content type without files
Fixes #9902
1 parent a7dc2e0 commit 8722a53

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,20 @@ pplx::task<web::http::http_response> ApiClient::callApi(
140140
if (!formParams.empty())
141141
{
142142
request.set_body(body_data);
143-
}
143+
}
144+
}
145+
else if (contentType == utility::conversions::to_string_t("multipart/form-data"))
146+
{
147+
MultipartFormData uploadData;
148+
for (auto& kvp : formParams)
149+
{
150+
uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second));
151+
}
152+
std::stringstream data;
153+
uploadData.writeTo(data);
154+
auto bodyString = data.str();
155+
auto length = bodyString.size();
156+
request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, utility::conversions::to_string_t("multipart/form-data; boundary=") + uploadData.getBoundary());
144157
}
145158
else
146159
{

0 commit comments

Comments
 (0)