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

How can I save an httpresponsemessage that contains a file attachment from a get api into bytes?

$
0
0

I have a get api where I receive the following content from httpresponsemessage, I wish to save that attachement as a byte in my sqlite database and reuse it later when the user wants to view the file. How can I download this attachment into bytes and afterward opens 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}

this is the code that im using to try to get the file into bytes. But when I'm saving in the sqlite database, I'm getting it same as above, 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 3637

Trending Articles