downloadDocument method Null safety
- int id
override
Allow to download a GlpiItemType.Document.
id
must be the id of the document to download.
Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#download-a-document-file
Implementation
@override
Future<String> downloadDocument(int id) async {
if (sessionToken!.isEmpty) {
throw Exception('No session token, initSession first');
}
final Map<String, String> headers = {
'Session-Token': sessionToken!,
'Content-Type': 'application/json',
'Accept': 'application/octet-stream',
...?appToken != null ? {'App-Token': appToken!} : null,
};
final uri = Uri.parse('$host/Document/$id');
final response = await _innerClient.get(uri, headers: headers);
if (response.statusCode != 200 && response.statusCode != 207) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
return Future.value(response.body);
}