1

Hello to everyone i hope you all good.

Im trying to upload a image to a server im using this: But it dosent work. So please help me, i would really appreciate it.

  Future<int> uploadFile(imageFile) async {
    try {
      var request = http.MultipartRequest(
        'POST',
        Uri.parse('http://10.0.2.2:8000/objects/'),
      );
      Map<String, String> headers = {"Content-type": "multipart/form-data"};
      request.files.add(
        http.MultipartFile(
          'file',
          imageFile.readAsBytes().asStream(),
          imageFile.lengthSync(),
          contentType: MediaType(
            'image',
            'jpeg',
          ),
        ),
      );
      request.headers.addAll(headers);
      request.fields.addAll({
        "app_label": "files",
        "app_model": "file",
      });
      print("request: " + request.toString());
      var res = await request.send();
      print("This is response:" + res.toString());
      return res.statusCode;
    } catch (err) {
      print(err);
      return 502;
    }
  }

Response from the server and vscode: https://ibb.co/2SMTBxJ

You can check the project here: https://github.com/bRUNS123/hydra

Also if someone know how to put the image without crop like the "finished" file. I the app you can take an image from the gallery or camera, then you have a preview and you can send or save to the gallery. But i created an option to avoid the crop image, but when i try to pass the information to not crop, nothing happen.

Also i wanna know if i can put all my void functions in a separated file.

Hope you have a great day!!

  • Have you tried something like [this answer](https://stackoverflow.com/questions/44841729/how-to-upload-images-to-server-in-flutter/49645074#49645074) ? And could you tell us exactly why it doesn't work? Does it give an error in the client, in the server, no error, or what happens? – UnaLuz Apr 10 '22 at 19:48
  • I update the image from the server and the vscode: https://ibb.co/2SMTBxJ – Bruno Franco Sentis Apr 10 '22 at 20:45
  • Vi que eras de Argentina. Te invito a Discord a ver si me puedes echar una mano y también compartir conocimiento : https://discord.gg/s6U8JjvV – Bruno Franco Sentis Apr 10 '22 at 22:51
  • Here is my[solution](https://stackoverflow.com/a/74255358/2462531) – Shailendra Madda Oct 30 '22 at 17:47

0 Answers0