[英].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.