Download File from Azure Blob Storage

你离开我真会死。 提交于 2019-12-04 06:32:33

Any reason you cannot have the client download the file directly from blob storage and use the built-in browser capability to save it? If the files are private, it is pretty easy to generate a SAS signature. This will offload the download from coming through your server and remove that overhead.

Here:

blob.DownloadToFile(photo.ImageName);

You need to tell it where to save the file and the name you want it to be:

blob.DownloadToFile("C:\mycutepuppy.jpg");

You could use System.Environment.SpecialFolder enum to figure out the folder based on the current system then append what you want the image name to be;

Here is a more complete example:

var imgPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), + photo.ImageName);

blob.DownloadToFile(imgPath);

This would save the image to the correct path where the user's desktop directory is. Here is the documentation on that enum for special folders.

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

I wonder what do you expect from this code, but especially in the case of different platform this would not work. I suggest that you use the DownloadToStream method instead. Then you can decide what to do with the stream. For example ask the user where does he want to save the file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!