当前位置:   article > 正文

C# Azure Blob 通过SAS Token 上传下载Blob_c# blob 上传

c# blob 上传
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using Azure;
  5. using Azure.Storage.Blobs;
  6. namespace TestCode
  7. {
  8. internal class Program
  9. {
  10. static async Task Main(string[] args)
  11. {
  12. //你的容器连接地址
  13. var blobContainerurl = "https://xxxxx.blob.core.chinacloudapi.cn/auto-yeeoffice-tst";
  14. //你的SAS Token
  15. 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";
  16. BlobContainerClient blobContainerClient = new BlobContainerClient(new Uri(blobContainerurl), new AzureSasCredential(sastoken));
  17. //上传Blob
  18. var uploadrespone= blobContainerClient.UploadBlob("test1.xlsx", File.OpenRead("D:/test1.xlsx"));
  19. //获取容器中的Blob
  20. var blobs=blobContainerClient.GetBlobs();
  21. foreach (var item in blobs)
  22. {
  23. Console.WriteLine(item.Name);
  24. BlobClient blobClient = blobContainerClient.GetBlobClient(item.Name);
  25. //下载Blob
  26. string localFilePath = $"d:\\blob\\{item.Name}";
  27. using (var fs = File.OpenWrite(localFilePath))
  28. {
  29. blobClient.DownloadTo(fs);
  30. }
  31. }
  32. }
  33. }
  34. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/138215
推荐阅读
相关标签
  

闽ICP备14008679号