http
http copied to clipboard
Multipart with headers per field
Currently when using Multipart fields, the headers that are sent for each fields are hard-coded and can't be changed by the caller. I need to be able to change the content-type for a specific field, declaring it as application/json.
I suggest to change the value type of the fields map inside MultipartRequest to a class that will hold the value and the headers, such as this:
class MultipartField {
final String value;
final Map<String, dynamic> headers;
MultipartField(this.value, {this.headers});
}
There isn't much left to do after that but to create a headers string from the map.
p.s. If anyone needs it until the issue is resolved, I personally copied the entire MulttipartRequest file to a new one and made the change. I also had to copy a few functions from the utils.dart page. Not the prettiest solution, but it works.
Can you please pass it. I' trying to send mixid multipart request with json object and image but no luck yet
Currently when using Multipart fields, the headers that are sent for each fields are hard-coded and can't be changed by the caller. I need to be able to change the content-type for a specific field, declaring it as application/json.
I suggest to change the value type of the fields map inside MultipartRequest to a class that will hold the value and the headers, such as this:
class MultipartField { final String value; final Map<String, dynamic> headers; MultipartField(this.value, {this.headers}); }There isn't much left to do after that but to create a headers string from the map.
p.s. If anyone needs it until the issue is resolved, I personally copied the entire MulttipartRequest file to a new one and made the change. I also had to copy a few functions from the utils.dart page. Not the prettiest solution, but it works.
@matanshukry
By any chance, could you give me your Custom MulttipartRequest.dart file?
@cj4luv
It's been a long time and I no longer have the project/file. However I re-created the file now for you, although I didn't fully test it - but I hope you get the idea:
https://gist.github.com/matanshukry/762dd679c349ebdec15c0b36e99f0cfa
@matanshukry
Thanks so much. You made my day.😀😀