如何在 flutter 中将 'application/octet-stream' 内容类型的图像发送到 Azure 认知服务

How to sent image in 'application/octet-stream' content type to Azure Cognitive Services in flutter

您好,我正在尝试使用 application/octet-stream' 内容类型将本地图像从 flutter 发送到 Azure 认知服务。 我遵循以下内容,但似乎缺少示例。唯一的例子是 'application/json'

Future getAnalisis() async {
    final uri =
        "https://****.cognitiveservices.azure.com/vision/v3.1/analyze?visualFeatures=Categories,Description&details=Landmarks";
    final respon = await http.post(
      uri,
      body: _file,
      headers: {
        'Ocp-Apim-Subscription-Key': '*****',
        'Content-Type': 'application/octet-stream'
      },
    );
    _imageVision = serializers.deserializeWith(
        ImageVision.serializer, jsonDecode(respon.body));
    notifyListeners();
  }

_file 来自

final pickedFile = await picker.getImage(source: ImageSource.camera);
if (pickedFile != null) _file = File(pickedFile.path);

我也试过下面的,当然是错误的

   body: jsonDecode({'url' : _file.path}),
      headers: {
        'Ocp-Apim-Subscription-Key': '*****',
        'Content-Type': 'application/json'
      },

目前我的错误信息是

 Invalid request body "File:
'/storage/emulated/0/Android/data/com.example.testRun/files/Pictures/7702e794-3a57-4a3a-a271-fd7c0964544d
4388330820207050041.jpg'".

body: _file.readAsBytesSync(),