我的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);
}
3条答案
按热度按时间9udxz4iz1#
你可以尝试添加
headers
,如下所示lc8prwob2#
093gszye3#
分享完整的代码,以供参考如何在头中添加授权: