1

For my project, I need to send image into my server in ngrok developed with Fast API. But everytime, it shows error 422: Unprocessable entity. My model is developed such that it expects input as image itself. It also works well with postman API. How can I solve this issue?

This is the code snippet which I used in flutter

Future<void> _sendImageToServer(File imageFile, String url) async {
  // Create a multipart request
  var request = http.MultipartRequest('POST', Uri.parse(url));

  // Add the image file to the request
  var image = await http.MultipartFile.fromPath('image', imageFile.path);
  request.files.add(image);

  try {
    // Send the request
    var response = await request.send();

    // Check the status code of the response
    if (response.statusCode == 200) {
      // Request was successful, handle response data
      print('Image uploaded successfully');
    } else {
      // Request failed, handle error
      print('Failed to upload image. Error: ${response.reasonPhrase}');
    }
  } catch (e) {
    // Handle any exceptions that occur during the request
    print('Error sending image: $e');
  }
}

Solution to this problem or alternate methods.

1

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.