http icon indicating copy to clipboard operation
http copied to clipboard

Multipart with headers per field

Open matanshukry opened this issue 6 years ago • 4 comments

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 avatar Jun 08 '19 12:06 matanshukry

Can you please pass it. I' trying to send mixid multipart request with json object and image but no luck yet

Blacktoviche avatar Nov 05 '19 17:11 Blacktoviche

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 avatar Mar 19 '22 08:03 cj4luv

@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 avatar Mar 19 '22 09:03 matanshukry

@matanshukry

Thanks so much. You made my day.😀😀

cj4luv avatar Mar 19 '22 09:03 cj4luv