0
의 오류 메시지를 반환합니다.이 사용자 정의 Odata 함수는 pdf 데이터베이스 다운로드에서 pdf를 다운로드 할 수 있습니다. 내가Odata 명명 파일은
1.with PDF 파일 이름의 이름이없는 몇 가지 문제가있다 "reportname.pdf는"이
로 response.pdf 이름2.return reportBinary의 오류 메시지에
[HttpGet]
[ODataRoute("GetDownloadReport(downloadId={downloadId})")]
public HttpResponseMessage GetDownloadReport(Guid downloadId)
var received = DateTime.UtcNow;
byte[] reportBinary = null;
string queryString = "SELECT report FROM downloads WHERE id = @downloadId ";
bool success = false;
using (SqlConnection conn = new SqlConnection(connectionString))
{
//get the binary from database
}
HttpResponseMessage response = null;
try
{
if (reportBinary == null)
return Request.CreateResponse(HttpStatusCode.Gone);
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(reportBinary);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {
FileName = "PORTName.pdf"
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.Gone);
}
}
죄송합니다. 하지만 여전히 첫 번째 문제는 다운로드 이름을 해결하지 않습니다 – NinjaDeveloper
브라우저에서 응답 헤더를 확인하십시오. Content-Disposition에 올바른 가치가있는 경우 문제는 webapi와 전혀 관련이 없습니다. – donMateo