简体   繁体   中英

.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.

    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

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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