upload static method

dynamic upload(
  1. String url,
  2. String name,
  3. String path
)

Implementation

static upload(String url, String name, String path) async {
  final config = CConfig();

  Map<String, String> headers = {
    'Authorization': "Bearer ${config.token}"
  };

  http.MultipartRequest request =
      http.MultipartRequest('POST', Uri.parse('${config.serverUrl}$url'));
  request.headers.addAll(headers);
  request.files.add(await http.MultipartFile.fromPath(name, path));

  var response = await request.send();
  var responsed = await http.Response.fromStream(response);

  if (response.statusCode == 200) {
    var responseData = await json.decode(utf8.decode(responsed.bodyBytes));

    return responseData['filename'];
  }

  return '';
}