如何打开另存为从云下载的对话框

时间:2013-04-16 07:05:49

标签: azure save cloud download filestream

我正在制作包含从云(Azure)存储下载文件的项目。我想打开另存为对话框,但没有得到它。我使用了以下代码。

enter code here // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob1");
        string FileName = "a3.jpg";
        string Filename = FileName.Substring(0, FileName.LastIndexOf("."));``
        Response.AppendHeader("Content-Disposition", "attachment; filename=" FileName);
        Response.TransmitFile(Server.MapPath("~/blockBlob/myblob1/" + Filename));
        Response.End();

        /* to download file from cloud

使用(var fileStream = System.IO.File.OpenWrite(@“C:\ Users \ prak \ Pictures \ ppp.JPG”))             {                 blockBlob.DownloadToStream(FILESTREAM);                 回复于( “
”);                 Response.Write(“成功下载!”);             } * /

请帮忙...... 提前谢谢

1 个答案:

答案 0 :(得分:0)

您需要将表单重定向到ashx处理程序,该处理程序将文件内容直接写入输出流。这不是Azure特有的,但如果从blob访问文件,则可能需要临时移动到Web服务器,以便您可以在“attachment; filename”中引用本地路径。

Response.Clear();
Response.ContentType = "image/jpeg";
Response.AddHeader( "Content-Disposition", "attachment;filename=\"myfile.jpg\"" );
// write file data to output stream here
Response.End();

另一种方法是使用HttpWebRequest,如以下帖子中所述:

Download/Stream file from URL - asp.net