私のasp.net Webアプリケーションの1つで、ユーザーに提供されているpdfファイルの場所を隠す必要があります。
したがって、CMS システム上のその場所からバイナリ コンテンツを取得し、バイト配列を Web ユーザーにフラッシュするメソッドを作成しています。
残念ながら、ストリームをダウンロードするときにエラーが発生します。
質問 1: 何が間違っていますか? 質問 2: このアプローチを使用して大きなファイルをダウンロードできますか?
private void StreamFile(IItem documentItem)
{
//CMS vendor specific API
BinaryContent itemBinaryContent = documentItem.getBinaryContent();
//Plain old .NET
Stream fileStream = itemBinaryContent.getContentStream();
var len = itemBinaryContent.getContentLength();
SendStream(fileStream, len, itemBinaryContent.getContentType());
}
private void SendStream(Stream stream, int contentLen, string contentType)
{
Response.ClearContent();
Response.ContentType = contentType;
Response.AppendHeader("content-Disposition", string.Format("inline;filename=file.pdf"));
Response.AppendHeader("content-length", contentLen.ToString());
var bytes = new byte[contentLen];
stream.Read(bytes, 0, contentLen);
stream.Close();
Response.BinaryWrite(bytes);
Response.Flush();
}