【发布时间】:2014-05-28 15:05:37
【问题描述】:
在我的 Asp.net MVC 中,当图像文件保存在实际文件夹结构中时,我使用了以下代码。
public FileResult DownloadFile(string imageName)
{
string fullPath = this.GetFullPath(imageName);
string contentType = " image/pjpeg";
return new FilePathResult(fullPath, contentType)
{
FileDownloadName = imageName
};
}
但是现在我们已经将图像移动到 Azure Blob,我们如何从那里下载图像。由于 FilePathResult dint 工作,我们尝试使用以下代码。
public ActionResult DownloadFile(string imgName)
{
string fullPath = imgName;
CloudStorageAccount account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConString"));
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = client.GetContainerReference(ConfigurationManager.AppSettings["BlobReference"]);
CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(imgName);
return Redirect(blockBlob.Uri.AbsoluteUri);
}
但是文件没有下载,而是在新窗口中打开,请指导我下载文件而不是在新窗口中打开。
【问题讨论】:
标签: c# asp.net asp.net-mvc azure download