0
votes

I'd like to upload an image binary via POST directly on the body of the request, without using form data(since I do not have access to modify the server side, to receive a dictionary or something like: image: [bla bla]), and without using File object, because at the moment you need a path to define it and I do not have one, I only have the binary saved in memory using the following Flutter plugin to get it: enter image description here

I am pretending to replicate this behavior on postman:

enter image description here

1

1 Answers

0
votes

So at the moment of this post, I tried using DIO library, but currently all different methods they provide did not work for me.

Following a similar question someone made for flutter itself(not mobile), one of the answers provided by: @Mehul Prajapati here: https://stackoverflow.com/a/64604174/8377232.

I did the the following:

Instead of Dio library, use http library like this:

Future<void> _uploadImage(Uint8List binaryImage) async {
Response response = await http.post(
  Uri.parse('<your url here> '),
  headers: {
    'Content-Type': "text/plain",
    'Accept': "*/*",
    'Content-Length': binaryImage.toString(),
    'Connection': 'keep-alive',
  },
  body: binaryImage,
);
}

And in order to get the binaryImage itself(which is an array of int8 numbers) I did the following: enter image description here This is the value I am sending to the method above, you might also need to modify your content-type according to your server API's need: to something like "image/jpeg" or whatever needed.

Thanks.