Flutter dio 图像上传不起作用会引发服务器 401 错误,但在邮递员中有效

Flutter dio image upload not working throws server 401 error, but works in postman

这是我的 post 带有 header 授权持有者令牌的人工请求。

我正在尝试上传图片,一切都按照文档 dio 中提到的设置进行设置,并且与 postman 参数完全相同,但是它抛出了 401 错误,它给了我一个未经授权的错误,似乎没有使用令牌来处理和上传文件。我正在阅读和移动 post 中提到的选项,但不幸的是我没有成功。 如果有人能给我一些指导并帮助我完成这个过程,我将不胜感激。

我的 dio 请求:

employeeAttachFile(File file) async {

  final SecureStorage _secureStorage = SecureStorage();
  final token = await _secureStorage.readToken('token');

  final String uri = '${ApiPaths.basisApi}${ApiPaths.addEmployeesFile}15';

  String fileName = file.path.split('/').last;
  print(fileName);

  FormData data = FormData.fromMap({
    "file": await MultipartFile.fromFile(
      file.path,
      filename: fileName,
    ),
  });

  Dio dio = new Dio(BaseOptions(
      headers: {"Authorization": token}, contentType: "application/json"));
  await dio.post(uri, data: data).then((response) {
    var jsonResponse = jsonDecode(response.toString());
    print(jsonResponse);
  }).catchError((error) => print(error));
}

这是我的错误:

尝试

{'Authorization': 'Bearer $token'}