0
我有這個自定義Odata函數從下載pdf數據庫下載pdf。我有一些問題Odata命名文件返回錯誤信息的
1.採用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