赞
踩
- 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);
- }
- }
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。