我的API要求是
URL:/ user / upload-profile-image
method = POST
标题-
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);
}
答案 0 :(得分:2)
您能否尝试像下面一样添加headers
Map<String, String> headers = { "Accesstoken": "access_token"};
final multipartRequest = new http.MultipartRequest('POST', Uri.parse(apiUrl))
multipartRequest.headers.addAll(headers);
multipartRequest.files.add(..)
答案 1 :(得分:0)
Photobook