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