Answers for "Flutter How to upload file to restApi with http package"

0

Flutter How to upload file to restApi with http package

uploadFile() async {
    var postUri = Uri.parse("<APIUrl>");
    var request = new http.MultipartRequest("POST", postUri);
    request.fields['user'] = 'blah';
    request.files.add(new http.MultipartFile.fromBytes('file', await File.fromUri("<path/to/file").readAsBytes(), contentType: new MediaType('image', 'jpeg')))

    request.send().then((response) {
      if (response.statusCode == 200) print("Uploaded!");
    });
  }
Posted by: Guest on February-22-2022

Code answers related to "Flutter How to upload file to restApi with http package"

Browse Popular Code Answers by Language