[Dart-dio-next] nullable fields sent when using multipart forms
See original GitHub issueThis is what is generated today with last version:
Future<Response<User>> saveProfile({
String? email,
String? firstName,
String? lang,
String? lastName,
String? mobile,
String? password,
MultipartFile? avatar,
CancelToken? cancelToken,
Map<String, dynamic>? headers,
Map<String, dynamic>? extra,
ValidateStatus? validateStatus,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
})
....
_bodyData = FormData.fromMap(<String, dynamic>{
r'email': encodeFormParameter(_serializers, email, const FullType(String)),
r'firstName': encodeFormParameter(_serializers, firstName, const FullType(String)),
r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
r'lastName': encodeFormParameter(_serializers, lastName, const FullType(String)),
r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
r'password': encodeFormParameter(_serializers, password, const FullType(String)),
r'avatar': avatar,
});
Problem with that is that null fields are still sent to the payload, and even worse encodeFormParameter
is forcing null field to be empty strings.
Basically here I don’t want an empty string sent as a new password ^^, so I’m getting 400 all the time because password is not correct.
I guess an easy fix would be to wrap then into a if like this:
_bodyData = FormData.fromMap(<String, dynamic>{
if(email != null) r'email': encodeFormParameter(_serializers, email, const FullType(String)),
if(firstName != null) r'firstName': encodeFormParameter(_serializers, firstName, const FullType(String)),
if(lang != null) r'lang': encodeFormParameter(_serializers, lang, const FullType(String)),
if(lastName != null) r'lastName': encodeFormParameter(_serializers, lastName, const FullType(String)),
if(mobile != null) r'mobile': encodeFormParameter(_serializers, mobile, const FullType(String)),
if(password != null) r'password': encodeFormParameter(_serializers, password, const FullType(String)),
if(avatar != null) r'avatar': avatar,
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
Receiving multipart form-data json parameter null
I receive in the controller both the file and the integer fine, but the json has all the fields as null. What could...
Read more >Configuring a resource to receive multipart/form-data parts ...
This task provides instructions for configuring a JAX-RS method to use and produce the multipart/form-data parts. The following example illustrates an HTML ...
Read more >Multipart request receives null content - MuleSoft Help Center
I am sending a multipart request as below to an email api- but the email api receives null content and throws and error...
Read more >How can i read multipart request parameters lazly?
String str = null; ... String returnParamValue = null; ... Why would you use a multipart form if you aren't uploading a file,...
Read more >Nullable Value Types - Visual Basic - Microsoft Learn
Sometimes you work with a value type that does not have a defined value in certain circumstances. For example, a field in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yea, already did that locally.
Yes wrapping if should be based on those two flags for sure. I saying it’s “easy” because we already have all the info in the template to make it work, so no heavy development in java or something ^^