2

When users upload a photo in my flutter app I want to call the function below to flag inappropriate images. I first upload the image to firebase storage then call this function using the generated image URL. For now, I just want it to print the results to make sure it works but nothing is printed.

  static void isAppropriate(String url) async {
    const String safeSearchURl =
        "https://vision.googleapis.com/v1/images:annotate";
    const apiKey = "HIDDEN";

    var headers = {
      'Content-Type': 'application/json',
      'Authorization': 'key=$apiKey'
    };

    var request = http.Request('POST', Uri.parse(safeSearchURl));

    request.body = '''
    {
      "requests": [
        {
          "image": {
            "source": {
              "imageUri": "$url"
            }
          },
          "features": [
            {
              "type": "SAFE_SEARCH_DETECTION"
            }
          ]
        }
      ]
    }''';
    request.headers.addAll(headers);

    http.StreamedResponse response = await request.send();

    if (response.statusCode == 200) {
      print(await response.stream.bytesToString());
    } else {
      print(response.reasonPhrase);
    }
  }
}

This is an example of what the printed response should be:

{
  "responses": [
    {
      "safeSearchAnnotation": {
        "adult": "UNLIKELY",
        "spoof": "VERY_UNLIKELY",
        "medical": "VERY_UNLIKELY",
        "violence": "LIKELY",
        "racy": "POSSIBLE"
      }
    }
  ]
}
Globe
  • 514
  • 3
  • 17

0 Answers0