简体   繁体   English

.net核心替代BlobStorageService

[英].net core replacement for BlobStorageService

i have tried using blob storage service but since i have used .net core and not framework its not working and its telling me that blob storage service is not there in your package.Kindly help me in resolving the issue. 我曾尝试使用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();
    }

You'll need to add a reference to Microsoft.Azure.Storage.Blob 您需要添加对Microsoft.Azure.Storage.Blob的引用

Then, in your code, you'll need to change: 然后,在代码中,您需要进行以下更改:

blobContainer = blobStorageService.GetCloudBlobContainer();

To something along the lines of: 类似于:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM