【发布时间】:2019-04-04 18:50:34
【问题描述】:
我正在尝试调整旧逻辑以支持来自 blob 的文件,谁能指导我如何打开存储在 azure blob 存储中的 pdf 文件。
我尝试搜索并找到了答案How to download a file to browser from Azure Blob Storage 这是使用 SAS 配置来做到这一点(如果我没记错的话)。
有什么办法可以转成字节吗?
从 windows 位置打开 pdf 文件的早期逻辑
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "inline; filename=" + mapid + ".pdf");
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] dataBytes = br.ReadBytes((int)(fs.Length - 1));
Response.BinaryWrite(dataBytes);
br.Close();
fs.Close();
我正在重写从 blob 读取文件的逻辑,下面的代码是我迄今为止尝试过的,
Byte[] dataBytes1;
CloudBlockBlob blobfile = GetStorageAccount(true).GetBlockBlobReference(filename);
blobfile.FetchAttributes();
using (StreamReader blobfilestream = new StreamReader(blobfile.OpenRead()))
{
dataBytes1 = blobfilestream.CurrentEncoding.GetBytes(blobfilestream.ReadToEnd());
}
Byte[] value = BitConverter.GetBytes(dataBytes1.Length - 1);
Response.BinaryWrite(value);
但文件未打开,出现“加载失败”错误。 如果这是一个好方法,谁能指导我?
【问题讨论】:
-
下面的答案对你有用吗?
-
关于这个问题的任何更新? :)
标签: c# azure azure-blob-storage