Skip to content
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

Add support for sending String as a file using MultipartFile.fromString #684

Open
mihir-kandoi opened this issue Jun 19, 2024 · 0 comments

Comments

@mihir-kandoi
Copy link

To send a JSON object as a String along with some Files, I need to explicitly change the generated .g.dart file from

_data.fields.add(MapEntry(
      'userDTO',
      userDTO,
    ));

to

_data.files.add(MapEntry(
      'userDTO',
      MultipartFile.fromString(
        userDTO,
        filename: 'userDTO',
        contentType: MediaType.parse('application/json'),
      ),
    ));

for the API call to work. Without it I always receive a 415 error saying that application/octet-stream is not supported as content type for the JSON parameter. I tried setting the content type to application/json in the Part annotation of the parameter to no avail. I also tried manually sending a MultipartFile object to the request but that didn't work as well.

I would like a provision in the package which allows us to send a String as a MultipartFile in the files fields of the FormData being generated by the generator.

Any alternative solution to fix this problem is also fine.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant