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