簡體   English   中英

.net核心替代BlobStorageService

[英].net core replacement for BlobStorageService

我曾嘗試使用Blob存儲服務,但由於我使用的是.net core,但沒有使用它的框架,因此它告訴我您的package中沒有blob存儲服務。請幫助我解決問題。

    BlobStorageService blobStorageService = new BlobStorageService();
    [HttpGet]
    public ActionResult Retrieve(string date)
    {
        date = "2018/07/25";
        CloudBlobContainer blobContainer = blobStorageService.GetCloudBlobContainer();
        string blobPath = $"QuickServiceWebApp006/{date}";
        CloudBlobDirectory directory = blobContainer.GetDirectoryReference(blobPath);
        List<string> blobs = new List<string>();
        //(prefix: "Folder1/Subfolder1", useFlatBlobListing: true)
        foreach (var blobItem in directory.ListBlobs(true))
        {
            //blobs.Add(blobItem.ToString());
            string[] pathArray = blobItem.Uri.ToString().Split('/');
            string blobName = $"{pathArray[pathArray.Length - 2] }/{ pathArray[pathArray.Length - 1]}";
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference($"{blobPath}/{blobName}");
            string text;
            using (var memoryStream = new MemoryStream())
            {
                //downloads blob's content to a stream
                blob.DownloadToStreamAsync(memoryStream);

                //puts the byte arrays to a string
                text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());

            }

            return View("Retrieve");
        }
        return View();
    }

您需要添加對Microsoft.Azure.Storage.Blob的引用

然后,在代碼中,您需要進行以下更改:

blobContainer = blobStorageService.GetCloudBlobContainer();

類似於:

CloudBlobContainer blobContainer = new CloudBlobContainer(
    uri, new StorageCredentials(accountName, key));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM