У меня есть веб-API, используемый для сохранения некоторых сгенерированных PDF-файлов.
Я использую следующий код:
[HttpPut]
[Route("getfile")]
public HttpResponseMessage GenerateFile(RequestView requestView)
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
using (var stream = new FileStream(@"C:\sample.pdf", FileMode.Open) { Position = 0 })
{
result.Content = new StreamContent(stream);
MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = "Sample.pdf" };
result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
result.Content.Headers.ContentDisposition.FileName = "Sample.pdf";
result.Content.Headers.ContentLength = stream.Length;
}
return result;
}
Но что я получаю:
![enter image description here](https://i.stack.imgur.com/BeO7g.png)
Ответ выглядит так:
%PDF-1.3
%âãÏÓ
1 0 obj
<<
/Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
>>
endobj
2 0 obj
<<
/Type /Outlines
/Count 0
>>
endobj
.
.
.
И заголовки:
![enter image description here](https://i.stack.imgur.com/ayAhX.png)
У кого-нибудь есть какие-нибудь подсказки, связанные с этим?
Спасибо.