Why am I getting 413 request entity too large error when I make post request in flutter?

Viewed 97

Im trying to make post request in flutter as shown below

uploadImage() async {
    print('inside uploadimage function');
    
    WidgetsBinding.instance.addPostFrameCallback((_) => setState((){isLoading = true;}  ));
    final request = http.MultipartRequest(
      "POST", Uri.parse('http://server/upload'));
    final headers = {"Content-type":"multipart/form-data"};
    request.files.add( http.MultipartFile('image1',
    widget.imagefile1!.readAsBytes().asStream(),widget.imagefile1!.lengthSync(),
    filename: widget.imagefile1!.path.split("/").last));
   
    request.files.add(http.MultipartFile('image2',
    imageFile!.readAsBytes().asStream(),imageFile!.lengthSync(),
    filename: imageFile!.path.split("/").last));
    request.headers.addAll(headers);

    final response = await request.send();
    http.Response res = await http.Response.fromStream(response);
    print('statuscode:');
    print(response.statusCode);
    print(response.reasonPhrase);    
  }

as a response I get error 413 request entity too large but when I make a request through POSTMAN i can successfully make a request with status 200 OK. as shown below image1

I'm not able to figureout why this happening any help or suggestion on how to solve this will be highly appreciated thanks

0 Answers
Related