-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List<int> is not sent as string in multipart request. #438
Comments
Hey 👋 You might want to look at this method for clues. Would be great if you can come up with a test case here. Also, this and this StackOverflow answer might be of some help. I'll take a deeper look into it once I find some free time. |
@techouse how do i test it? i tried referencing it like this:
and i had this error:
|
You need to also specify the path. chopper:
git:
url: https://github.com/techouse/chopper.git
ref: fix/issue-438-multipart-list
path: chopper |
yeah right, i did that and i got this now:
even if i change the dependency of the generator to |
You might need to put that into dependency_overrides:
chopper:
git:
url: https://github.com/techouse/chopper.git
ref: fix/issue-438-multipart-list
path: chopper |
This doesn't fix it, it seems your solution is changing the field name to contain an index, causing the backend to not detect the field. when I printed the request body on the backend i received this:
but when i try with postman i receive this:
|
That is the only solution.
It's pretty standard HTTP practice. If all of them have the same name they would overwrite each other. As the values need to be essentially stringified, a final List<int> ints = [1, 2, 3]; would become final List<String> ints = [
'lorem',
'ipsum',
'dolor, something after an in string comma',
]; it would become |
Why is the case of postman working properly? The backend receives it as a list of strings as you can see, in my previous answer, and it works just fine... :/ |
What's the actual HTTP request that postman makes? And FYI I did try using something like This is how they do it in retrofit. |
this is the dart code that postman proposes:
|
Hmm, ok. I've updated the code. Pull the repo and try again. |
I still get the same output as the previous one... |
Yeah, I've only fixed it for the files. The dictionary with the integers, as in your example, can't have repeated keys. What's the cURL code it generates? |
cURL:
|
While that will work with cURL it won't work with MultipartRequest fields because they are a dictionary and keys can't be repeated. |
Then why does this snippet, which uses dio, works just fine?
on the backend i receive this (just like postman):
|
Because
This has been mentioned previously in #77 where @humazed provided a solution @Post(path: "store/orders")
@multipart
Future<Response<Order>> createTripOrder(
@Part("trip") int trip,
@PartFile("images[]") List<MultipartFile> images,
); What you want is not possible with The solution I implemented is exactly the same as suggested here dart-lang/http#277 (comment) As I said above, using this kind of annotation Effectively you have 2 options:
|
I have this multipart request:
the classes part, is being sent as a string, and causing the backend to respond with http 400 with this error:
anyway to fix this issue?
Also, how to send multiple files under the same field name? uncommenting the last line makes it fail (without throwing any errors).
The text was updated successfully, but these errors were encountered: