【发布时间】:2021-05-20 17:07:23
【问题描述】:
我有这个将文件发送到服务器的 put 请求,它需要一个令牌作为标头的一部分。请问如何在使用 Dio().put 发出请求时将此令牌添加到标头?
Future<String> sendImage(File file) async {
String token = storage.read('token');
String fileName = file.path.split('/').last;
FormData formData = FormData.fromMap({
"CustomerProfilePicture":
await MultipartFile.fromFile(file.path, filename: fileName),
});
Response response =
await Dio().put(
'$BASE_URL/Customers/Picture', data: formData);
return response.statusMessage;
}
【问题讨论】: