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


Hi I’am trying to sent a local image using application/octet-stream’ content type to Azure Cognitive Services from flutter.
I have follow the following but it seem to be missing the example. The only example is for ‘application/json’

Future getAnalisis() async {
    final uri =
    final respon = await
      body: _file,
      headers: {
        'Ocp-Apim-Subscription-Key': '*****',
        'Content-Type': 'application/octet-stream'
    _imageVision = serializers.deserializeWith(
        ImageVision.serializer, jsonDecode(respon.body));

and the _file is from

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

I also have tried the following but it of course error

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

and currently my error message is

 Invalid request body "File:


body: _file.readAsBytesSync(),

Answered By – Lee3

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *