deleteItem method
Delete a file or a directory
Implementation
Future<String> deleteItem(bool fileFlag, String itemLoc) async {
String contentType = '';
/// Set up directory or file parameters
if (fileFlag) {
/// This is a file (resource)
contentType = 'text/turtle';
} else {
/// This is a directory (container)
contentType = 'application/octet-stream';
}
String encKeyUrl = webId.replaceAll('profile/card#me', itemLoc);
String dPopToken =
genDpopToken(encKeyUrl, rsaKeyPair, publicKeyJwk, 'DELETE');
final createResponse = await http.delete(
Uri.parse(encKeyUrl),
headers: <String, String>{
'Accept': '*/*',
'Authorization': 'DPoP $accessToken',
'Connection': 'keep-alive',
'Content-Type': contentType,
'DPoP': dPopToken,
},
);
if (createResponse.statusCode == 200 || createResponse.statusCode == 205) {
// If the server did return a 200 OK response,
// then parse the JSON.
return 'ok';
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
throw Exception('Failed to delete file! Try again in a while.');
}
}