У меня есть веб-приложение, и пользователь должен иметь возможность загружать файлы, которые хранятся в хранилище Azure.
public class FileDownloader
{
private string constring = "myconnectionstring";
public async Task download(string fileName, string directoryName)
{
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(constring);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference("myreference");
string userName = Environment.UserName;
if (await share.ExistsAsync())
{
// Get a reference to the root directory for the share.
CloudFileDirectory rootDir = share.GetRootDirectoryReference();
// Get a reference to the directory we created previously.
CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(directoryName);
// Ensure that the directory exists.
if (await sampleDir.ExistsAsync())
{
// Get a reference to the file we created previously.
CloudFile file = sampleDir.GetFileReference(fileName);
// Ensure that the file exists.
if (await file.ExistsAsync())
{
await file.DownloadToFileAsync(string.Format("C:/Users/" + userName + "/Downloads/{0}", fileName), FileMode.Create);
}
}
}
}
catch (Exception ex)
{
}
}
}
Это мой код.
Оно отлично работает, когда я запускаю приложение в своей локальной среде (localhost), но когда я его развертываю и размещаю в Azure, оно не загружает файлы.