flutter save json to file

Solutions on MaxInterview for flutter save json to file by the best coders in the world

showing results for - "flutter save json to file"
Keenan
06 Oct 2017
1     Future<ApiResponse<bool>> uploadfile(File file) async {
2
3    var stream = new http.ByteStream(DelegatingStream(file.openRead()));
4    var length = await file.length();
5    var uri = Uri.parse("Enter your URL");
6    var request = new http.MultipartRequest("POST", uri);
7    var multipartFile = new http.MultipartFile('data', stream, length, filename: basename(file.path));
8    request.files.add(multipartFile);
9    await request.send().then((response) {
10      response.stream.transform(utf8.decoder).listen((value) {
11      file.delete();
12        print(value);
13      });
14
15    }).catchError((e) {
16      print(e);
17    });
18  }
19