Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3690

How can I save an HttpResponseMessage as binary?

$
0
0

From a GET API I receive JSON content with HttpResponseMessage. I wish to save that attachment as binary in my SQLite database. How can I do this and open it for the user to view?

{"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}

When saving to database I'm getting it in JSON format:

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);

Viewing all articles
Browse latest Browse all 3690

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>