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

I cannot set a content-type of a form-data field #2064

Closed
MarinF00 opened this issue Dec 11, 2023 · 5 comments
Closed

I cannot set a content-type of a form-data field #2064

MarinF00 opened this issue Dec 11, 2023 · 5 comments

Comments

@MarinF00
Copy link

Package

dio

Version

5.4.0

Operating-System

Android

Output of flutter doctor -v

No response

Dart Version

No response

Steps to Reproduce

  formData.fields.add(MapEntry(
      'data',
      jsonEncode(bpData.toJson())
  ));

Expected Result

  formData.fields.add(MapEntry(
      'data',
      {value: jsonEncode(bpData.toJson(),
     contentType: 'application/json'}

)
));

Actual Result

Could not resolve parameter [0] in public org.springframework.http.ResponseEntity<?> com.bp.api.controllers.PdfController.generatePdf(com.bp.api.models.dtos.Pdf,org.springframework.web.multipart.MultipartFile,org.springframework.web.multipart.MultipartFile,org.springframework.web.multipart.MultipartFile,org.springframework.web.multipart.MultipartFile,org.springframework.web.multipart.MultipartFile,java.util.List<org.springframework.web.multipart.MultipartFile>): Content-Type 'application/octet-stream' is not supported
api-bp | 2023-12-11T14:58:50.733Z WARN 55 --- [nio-8080-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/octet-stream' is not supported]
api-bp | 2023-12-11T14:58:50.734Z DEBUG 55 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : Completed 415 UNSUPPORTED_MEDIA_TYPE

@MarinF00 MarinF00 added h: need triage This issue needs to be categorized s: bug Something isn't working labels Dec 11, 2023
@AlexV525
Copy link
Member

Only MultipartFile contains content-type. What is your purpose?

@AlexV525 AlexV525 added the h: need more info Further information is requested label Dec 14, 2023
@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2023
@AlexV525 AlexV525 added i: no useful information i: no response and removed h: need more info Further information is requested h: need triage This issue needs to be categorized s: bug Something isn't working labels Dec 26, 2023
@MarinF00
Copy link
Author

I am trying to pass json object and I need to give it a content-type as you can see in the example but its not possible.
content-file should be supported if the data is just text. Right now there is no way to set application-json type when trying to pass json object.

@AlexV525
Copy link
Member

Won't MultipartFile.fromBytes work?

@MarinF00
Copy link
Author

It won't.

@AlexV525
Copy link
Member

Why? MultipartFile.fromBytes(utf8.encode(jsonEncode(json)), contentType: MediaType('application', 'json')) should work for your case.

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

No branches or pull requests

2 participants