我有AzureBlobService.cs:
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
namespace AzureBlob.API.Service
{
public class AzureBlobService
{
BlobServiceClient _blobClient;
BlobContainerClient _containerClient;
string azureConnectionString = "<Primary Connection String>";
public AzureBlobService()
{
_blobClient = new BlobServiceClient(azureConnectionString);
_containerClient = _blobClient.GetBlobContainerClient("apiimages");
}
public async Task<List<Azure.Response<BlobContentInfo>>> UploadFiles(List<IFormFile> files)
{
var azureResponse = new List<Azure.Response<BlobContentInfo>>();
foreach (var file in files)
{
string fileName = file.FileName;
using (var memoryStream = new MemoryStream())
{
file.CopyTo(memoryStream);
memoryStream.Position = 0;
var client = await _containerClient.UploadBlobAsync(fileName, memoryStream, default);
azureResponse.Add(client);
}
};
return azureResponse;
}
public async Task<List<BlobItem>> GetUploadedBlobs()
{
var items = new List<BlobItem>();
var uploadedFiles = _containerClient.GetBlobsAsync();
await foreach (BlobItem file in uploadedFiles)
{
items.Add(file);
}
return items;
}
}
}
如何更改此代码以使用SAS令牌连接到Azure CDN文件夹?
1条答案
按热度按时间5uzkadbs1#
如何更改此代码,以便使用SAS令牌连接到Azure CDN文件夹?
要使用**
SAS token
**而不是连接字符串,您可以遵循本文档,它将帮助您连接存储帐户与SAS令牌。您可以尝试下面的代码使用SAS令牌连接存储帐户以上传文件和检索上传的blob。
代码: