我的API要求是
网址:/ 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);
}
你可以试着像下面这样添加headers
Map<String, String> headers = { "Accesstoken": "access_token"};
final multipartRequest = new http.MultipartRequest('POST', Uri.parse(apiUrl))
multipartRequest.headers.addAll(headers);
multipartRequest.files.add(..)