ziobudda

Untitled

Sep 17th, 2020 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.89 KB | None | 0 0
  1. Future<void> _takePicture(source) async {
  2.     final prefs = await SharedPreferences.getInstance();
  3.     final picker = ImagePicker();
  4.     final imageFile = await picker.getImage(source: source);
  5.  
  6.     if (imageFile == null) {
  7.       return;
  8.     }
  9.  
  10.     var request = http.MultipartRequest(
  11.         'POST', Uri.parse('https://XXXX.xXXX/api/vehicle/addPhoto'));
  12.     request.headers['Authorization'] =
  13.         'Bearer ' + prefs.getString('access_token');
  14.     request.files
  15.         .add(await http.MultipartFile.fromPath('file', imageFile.path));
  16.  
  17.     setState(() {
  18.       this._saving = true;
  19.     });
  20.     var res = request.send();
  21.     res.then((response) {
  22.       print("dentro then");
  23.       print(response.stream.toString());
  24.     });
  25.     print("reasonPhrase");
  26.     print(res.toString());
  27.     print("status code");
  28.     setState(() {
  29.       this._saving = false;
  30.     });
  31.  
  32.     return;
  33.   }
Add Comment
Please, Sign In to add comment