upload method

Future<PictrsUpload> upload({
  1. required String filePath,
  2. required String auth,
})

Implementation

Future<PictrsUpload> upload({
  required String filePath,
  required String auth,
}) async {
  final req = http.MultipartRequest('POST', Uri.https(host, extraPath))
    ..files.add(await http.MultipartFile.fromPath('images[]', filePath));
  req.headers['Cookie'] = 'jwt=$auth';

  final res = await req.send();
  final Map<String, dynamic> body =
      jsonDecode(utf8.decode(await res.stream.toBytes()));
  body['instance_host'] = host;

  return PictrsUpload.fromJson(body);
}