How to send an image to an api in dart/flutter?

前端 未结 3 823
盖世英雄少女心
盖世英雄少女心 2020-12-19 08:58

I saw other questions, but thats not what i want, i dont want to upload an image to a server, i dont want to convert to base64...

I only want to post a file in a fo

3条回答
  •  [愿得一人]
    2020-12-19 09:14

    If you are sending the image to PHP Laravel Server. Try reducing the size of the image while sending it to the server. I used Image Picker package to reduce the size of the image.

    var image = await ImagePicker.pickImage(source: imageSource, imageQuality: 50, maxHeight: 500.0, maxWidth: 500.0);
    

    Then create a multipart file with that image, add it to form data, and send the form data to the server using post request with dio library. See @Elialber Lopes answer for sending the data.

    It worked for me.

提交回复
热议问题