using System;
using System.IO;
using System.Threading.Tasks;
using Azure;
using Azure.Storage.Blobs;
namespace TestCode
{
internal class Program
{
static async Task Main(string[] args)
{
//你的容器连接地址
var blobContainerurl = "https://xxxxx.blob.core.chinacloudapi.cn/auto-yeeoffice-tst";
//你的SAS Token
var sastoken = "sp=racwdli&st=2023-08-03T07:11:48Z&se=2030-08-03T15:11:48Z&spr=https&sv=2022-11-02&sr=c&sig=erereqQd0sTqNT4a6%2FhvaV7qqsU4XB1dGhQtDVjFAuFsho%3D";
BlobContainerClient blobContainerClient = new BlobContainerClient(new Uri(blobContainerurl), new AzureSasCredential(sastoken));
//上传Blob
var uploadrespone= blobContainerClient.UploadBlob("test1.xlsx", File.OpenRead("D:/test1.xlsx"));
//获取容器中的Blob
var blobs=blobContainerClient.GetBlobs();
foreach (var item in blobs)
{
Console.WriteLine(item.Name);
BlobClient blobClient = blobContainerClient.GetBlobClient(item.Name);
//下载Blob
string localFilePath = $"d:\\blob\\{item.Name}";
using (var fs = File.OpenWrite(localFilePath))
{
blobClient.DownloadTo(fs);
}
}
}
}
}
C# Azure Blob 通过SAS Token 上传下载Blob
最新推荐文章于 2023-12-01 15:13:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)