Azure blob 文件下载
生活随笔
收集整理的這篇文章主要介紹了
Azure blob 文件下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、獲取所有Azure 容器中的資源文件
private string azureConnectionStrig = " DefaultEndpointsProtocol = https; AccountName =" + storageConfig.AccountName + " ; AccountKey =" + storageConfig.AccesssKey; private string AccountName =storageConfig.AccountName;private CloudStorageAccount _storageAccount;private CloudBlobContainer _cloudBlobContainer; public async Task<List<string>> GetResourceURL() {BlobContinuationToken blobContinuationToken = null;List<string> resourceURI = new List<string>();do{if (await TryGetRemote()){var results = await _cloudBlobContainer.ListBlobsSegmentedAsync(null, blobContinuationToken);blobContinuationToken = results.ContinuationToken;foreach (IListBlobItem item in results.Results){resourceURI.Add(item.Uri.ToString());}}} while (blobContinuationToken != null); return resourceURI; } public async Task<bool> TryGetRemote(){if (CloudStorageAccount.TryParse(azureConnectionStrig, out _storageAccount)){CloudBlobClient cloudBlobClient = _storageAccount.CreateCloudBlobClient();try{_cloudBlobContainer = cloudBlobClient.GetContainerReference(AccountName);BlobContainerPermissions permissions = new BlobContainerPermissions{PublicAccess = BlobContainerPublicAccessType.Blob};Task task = _cloudBlobContainer.SetPermissionsAsync(permissions);//超時1秒if ((await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(1)))) != task){Console.Write("連接服務器超時");return false;} return true;}catch (WebException e){Console.Write("更新服務器連接失敗" + e.ToString());}catch (Exception e){Console.Write("初始化azureblob失敗" + e.ToString());}}return false;}2、獲正確的支援文件
?2.1? 定義文件屬性
public interface IFile{bool IsCorrectName();int GetVersion();void Clean();string GetName();}2.2獲取文件
2、獲取資源文件跟進行比對
private Dictionary<string, T> GetRemoteNewerFile(List<T> azureFiles){Dictionary<string, T> matches = new Dictionary<string, T>();foreach (var azureFile in azureFiles){if (matches.ContainsKey(azureFile.GetName())){if (matches[azureFile.GetName()].GetVersion() < azureFile.GetVersion()){matches[azureFile.GetName()] = azureFile;}}else{matches.Add(azureFile.GetName(), azureFile);}}return matches;}...........待續
總結
以上是生活随笔為你收集整理的Azure blob 文件下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精选10个用于Java开发Spring
- 下一篇: Linux - 怎么实现大文件传输