1
Chrome에서 파일을 미리 보려고하지만 계속 다운로드 중입니다.ByteArrayContent 결과를 반환하는 HttpResponseMessage - Chrome에서 문서 미리보기
[HttpGet]
[ResponseType(typeof(ByteArrayContent))]
public HttpResponseMessage Download([FromUri] int uploadId)
{
try
{
Upload upload = UploadController.LoadByPrimaryKey(uploadId);
var path = upload.FullPath + "\\" + upload.UploadGuid + upload.Extension;
var mimeType = MimeTypeMap.GetMimeType(upload.Extension);
MemoryStream pdf = new MemoryStream(File.ReadAllBytes(path));
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(pdf.ToArray());
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
result.Content.Headers.ContentDisposition.FileName = upload.OriginalFileName;
result.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
return result;
}
catch (Exception ex)
{
//..
}
}
이것은 피들러의 흔적입니다.
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 793708
Content-Type: application/pdf
Expires: -1
Server: Microsoft-IIS/10.0
Access-Control-Allow-Origin: http://localhost:6701
Access-Control-Allow-Credentials: true
Content-Disposition: inline; filename="1451048-Customer Acceptance.pdf"
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 19 Jun 2016 10:52:35 GMT
...
나는 Open PDF file in browser rather than downloading pdf file 및 How to force files to open in browser instead of download (pdf)?을 보았다하지만, 난 여전히 문제가 발생하고있다.
도움을 주시면 감사하겠습니다.