小编Myn*_*pet的帖子

从 Blob 存储下载文件 .net core Azure Function C#

注:此为分享。 几天前,我尝试使用 Azure Function 构建一个操作“blob 存储操作 CRUD”的 API,我研究了一种解决下载操作的解决方案,因为我发现的大多数互联网解决方案都在本地工作,但在将我的函数部署到 Web 服务器时需要授予权限路径来创建文件并在本地下载,这会生成错误:“访问路径被拒绝”。然后我解决了通过HTTP响应下载Azure函数V2,C#.net core 2.1这是我工作的基本代码,我希望它能帮助你......

using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Auth;
using System.IO;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Net;

namespace BloApi
{
    public static class BlobOperations
    {
        [FunctionName("DownloadBlob")]
        public static async Task<HttpResponseMessage> DownloadBlob(
          [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "DownloadBlob/{name}")] HttpRequest req, string name)
        {
            StorageCredentials storageCredentials = new StorageCredentials("Storage",
                "CamEKgqVaylmQ.....ow2VHlyCww==");
            CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
            CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("MyBlobContainer");
            var blobName = name;
            CloudBlockBlob block …
Run Code Online (Sandbox Code Playgroud)

blob azure

8
推荐指数
0
解决办法
4109
查看次数

标签 统计

azure ×1

blob ×1