Я хочу добавить заголовок с access_token для изображения загрузки флаттера - PullRequest
0 голосов
/ 24 августа 2018

Мои требования к API:

URL: / user / upload-profile-image

method = POST

header -

Accesstoken: "access_token"

content-type = multipart / form-data

Это мой код:

Future getUploadImg(File _image) async {

  String apiUrl = '$_apiUrl/user/upload-profile-image';

  final length = await _image.length();

  final request = new http.MultipartRequest('POST', Uri.parse(apiUrl))
      ..files.add(new http.MultipartFile('avatar', _image.openRead(), length));

  http.Response response = await http.Response.fromStream(await request.send());

  print("Result: ${response.body}");

  return JSON.decode(response.body);

}

1 Ответ

0 голосов
/ 24 августа 2018

Можете ли вы попробовать добавить headers, как показано ниже

Map<String, String> headers = { "Accesstoken": "access_token"};

final multipartRequest = new http.MultipartRequest('POST', Uri.parse(apiUrl))
multipartRequest.headers.addAll(headers);
multipartRequest.files.add(..)
...