0

below is the code that I tried but it didn't work, how to insert header on MultipartRequest?

      var id = prefs.getInt('id');
      var token = prefs.getString('accessToken');
      var uri = Uri.parse('https://url.com/submit/$id');
      var headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer $token'
      };

      var request = http.MultipartRequest('POST', uri);
      request.files.add(
        await http.MultipartFile.fromPath('file', _files.first.path.toString()),
      );
      var response = await request.send();
Jon
  • 109
  • 2
  • 10

1 Answers1

0

Headers is a map attribute of the request object, you can simply use map methods on it:

request.headers.addAll(headers)
Mirkuzzz
  • 48
  • 5