Из API GET я получаю контент JSON с помощью HttpResponseMessage. Я хочу сохранить это вложение как двоичный файл в своей базе данных SQLite. Как я могу это сделать и открыть для просмотра пользователем?
{"Version":"1.1","Content":{"Headers":[{"Key":"Content-Disposition","Value":["attachment; filename=\"Formulaire de remise HDD_hors MINARM.pdf\""]},{"Key":"Content-Type","Value":["application/pdf"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"TrailingHeaders":[],"RequestMessage":null,"IsSuccessStatusCode":true}
При сохранении в базу данных я получаю его в формате JSON:
var getFiles = new HttpRequestMessage(HttpMethod.Get, $"{Constants.getTicketApi}/{data.Id}/Document?filename={filename}");
HttpResponseMessage fileresponse = await _httpClient.SendAsync(getFiles);
{
if (fileresponse.IsSuccessStatusCode)
{
var filecontent = fileresponse.Content.ReadAsByteArrayAsync().Result;
FilesDB file = new FilesDB
{
TicketId = data.Id,
FileDescriptorID = fdId,
Data = filecontent
};
await _context.SaveData(file);
}
}
await _context.SaveData(filedescriptor);
Подробнее здесь: https://stackoverflow.com/questions/786 ... -as-binary