fetchFile method

Future<String> fetchFile(
  1. String fileLoc
)

Get a file content from the server

Implementation

Future<String> fetchFile(String fileLoc) async {
  String fileUrl = webId.replaceAll('profile/card#me', fileLoc);
  String dPopToken = genDpopToken(fileUrl, rsaKeyPair, publicKeyJwk, 'GET');

  final profResponse = await http.get(
    Uri.parse(fileUrl),
    headers: <String, String>{
      'Accept': '*/*',
      'Authorization': 'DPoP $accessToken',
      'Connection': 'keep-alive',
      'DPoP': dPopToken,
    },
  );

  if (profResponse.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the JSON.
    return profResponse.body;
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception('Failed to fetch file content! Try again in a while.');
  }
}