我需要将一个文件从 Azure Blob 存储复制到我的 Azure 托管网站的“内容”文件夹中,我正在努力完成这项工作!任何帮助将不胜感激。该代码在我的本地服务器上运行良好,但在 Azure 上托管时失败。
这是我的功能:
public bool CopyFromAzure(string myContainer, string fileName, string filePath)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(myContainer);
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
try
{
// Save blob contents to a file.
// --> here is where an error happens !! on System.IO.File.Create
// The value of "filePath" is: F:\sitesroot\0\Content\tmp\file_2cfe0a3d-fa7a-4ab4-a665-cdebd90567d4.pdf
using(FileStream fs= System.IO.File.Create(@filePath))
{
blockBlob.DownloadToStream(fs);
}
}
catch (Exception e)
{
return false;
}
return true;
}
问题:这可以链接到 Azure 或我的网站配置中的安全首选项吗?
谢谢