get method

Get the file object at the server for this FileStorageReference.

Implementation

Future<CarpFileResponse> get() async {
  assert(id > 0);
  final String url = "$fileEndpointUri/$id";

  http.Response response =
      await httpr.get(Uri.encodeFull(url), headers: headers);
  int httpStatusCode = response.statusCode;
  Map<String, dynamic> map =
      json.decode(response.body) as Map<String, dynamic>;

  print(response.body);

  switch (httpStatusCode) {
    case 200:
      {
        return CarpFileResponse._(map);
      }
    default:
      // All other cases are treated as an error.
      {
        throw CarpServiceException(
          httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
          message: map["message"].toString(),
          path: map["path"].toString(),
        );
      }
  }
}