我在Azure中有图像需要使用pdfJet以pdf格式添加。
这是我在磁盘上读取图像时使用的代码,但是我有很多图像,从Azure下载它们没有意义。
Image image = new Image(objects, new BufferedStream(new FileStream(LocalPath + "image.PNG", FileMode.Open, FileAccess.Read)), ImageType.PNG);
PS:这是在asp.net webforms中完成的。
谢谢您的帮助。
我现在使用以下函数来阅读PDF:
public MemoryStream DownloadToMemoryStream(DTO.BlobUpload b)
{
CloudStorageAccount storageAccount = Conn.SNString(b.OrgID);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(b.Container);
CloudBlockBlob blob = container.GetBlockBlobReference(b.FileName);
var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),//assuming the blob can be downloaded in 10 miinutes
}, new SharedAccessBlobHeaders()
{
ContentDisposition = "attachment; filename=file-name"
});
using (MemoryStream ms = new MemoryStream())
{
blob.DownloadToStream(ms);
return ms;
}
}
在我使用的aspx页面中:
MemoryStream pdfScript = B.DownloadToMemoryStream(b);
阅读流:
SortedDictionary<Int32, PDFobj> objects = pdfFinalScript.Read(pdfScript);
但是我收到错误消息:无法访问已关闭的流
我已经看过如何打开流但没有设法做到这一点。
你能帮帮忙吗,谢谢
根据您的描述,您将从Azure下载blob。您可以通过以下几种方式参考。
创建具有读取权限和Content-Disposition标头集的共享访问签名,并根据该URL创建blob URL并使用该URL。在这种情况下,blob内容将直接从存储流式传输到客户端浏览器。
2.获得blob和DownloadFileFromBlob。
3.下载文件到exactly path in local。
网上表格:
您可以使用Response.Redirect(blobUrl);
重定向blob网址并下载它。
在.aspx中:
<asp:Button ID="Button1" runat="server" Text="Click Me" OnClick="Button1_Click" />
在aspx.cs中:
protected void Button1_Click(object sender, EventArgs e)
{
CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("accountname", "accountkey"), true);
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("container");
var blob = container.GetBlockBlobReference("text.PNG");
var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),//assuming the blob can be downloaded in 10 miinutes
}, new SharedAccessBlobHeaders()
{
ContentDisposition = "attachment; filename=file-name"
});
using (MemoryStream ms = new MemoryStream())
{
blob.DownloadToStream(ms);
Image image = new Image(objects, ms, ImageType.PNG);
}
}