Multipart post request doesn't work
jaumard opened this issue · 2 comments
jaumard commented
Generated retrofit code is using this:
Future<User> saveProfile(
int id,
String email,
String firstname,
String lang,
String lastname,
String mobile,
String password,
MultipartFile avatar) async {
var req = base.post
.metadata({
"auth": [
{
"type": "apiKey",
"name": "Bearer",
"keyName": "Authorization",
"where": "header",
}
],
})
.path(basePath)
.path("/api/v1/user")
.multipart({"id": id})
.multipart({"email": email})
.multipart({"firstname": firstname})
.multipart({"lang": lang})
.multipart({"lastname": lastname})
.multipart({"mobile": mobile})
.multipart({"password": password})
.multipart({"avatar": avatar});
return req.go(throwOnErr: true).map(decodeOne);
}
But this fails with Exception invalid body !
Because of this code in routes.dart
:
if (_body is String ||
_body is List<int> ||
_body is Map<String, String> ||
_body == null) {
return (getClient ?? globalClient)
.post(getUrl, headers: getHeaders, body: _body);
} else {
throw Exception('Invalid body!');
}
Here the body is Map<String, Multipart>
so it look like the case is not handled
@tejainece any idea ?
rhalff commented
Are you sure you're using a recent version of jaguar_resty?
If I look at the source it does contain code to handle multipart.
https://github.com/Jaguar-dart/client/blob/master/resty/lib/routes/routes.dart#L680-L714
Patch has similar (duplicate) code.
jaumard commented
You're right my version is 2.10.12 and last is 2.10.14 with those changes. Thanks !!