1

I try send image using flutter chopper. I try do it at 2 different ways, but none work.

  @Post(path: '/photos')
  @multipart
  Future<Response> postFile(
      @Header('token') String token, @PartFile('file') List<int> bytes);

  @Post(path: '/photos')
  @multipart
  Future<Response> postFileOnePiece(
    @Header('token') String token,
    @Body() Map<String, dynamic> body,
  );
sendImageTest() async {
            final bytes = (await File(
                        Provider.of<MyLocalStorage>(context, listen: false)
                            .temporaryMethodGetFullPathOfFirstPhoto())
                    .readAsBytes())
                .toList();
// ### 1
            Provider.of<ApiService>(context, listen: false)
                .postFileOnePiece(
                    Provider.of<Token>(context, listen: false).token,
                    {"file": bytes});

// ### 2
            Provider.of<ApiService>(context, listen: false).postFile(
                Provider.of<Token>(context, listen: false).token, bytes);
}

I test my API at Postman, and this setup is working:

enter image description here

enter image description here

sosnus
  • 968
  • 10
  • 28

0 Answers0