Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add authorization header in MultipartRequest in dart

Tags:

flutter

dart

I am using MultipartRequest in dart in order to upload files to API. However I need to add an authorization header to my request. The problem that i am facing is that the header attribute is final and I can't overwrite it. How can I fix that? Thank you!

like image 831
Sami Kanafani Avatar asked Oct 07 '18 18:10

Sami Kanafani


2 Answers

headers is a Map, so add the key/value.

http.MultipartRequest request =
    new http.MultipartRequest('POST', Uri.parse(url));
request.headers['authorization'] = 'the auth header value';
like image 67
Richard Heap Avatar answered Nov 11 '22 02:11

Richard Heap


Alternatively, if you want to pass all the preconfigured header (key, value) Map, from your, let's say _headers, you can do something like:

_headers.forEach((k, v) {
  request.headers[k] = v;
});
like image 3
valvoline Avatar answered Nov 11 '22 02:11

valvoline