0

我正在将 1MB 块中的大 blob 上传到 Azure 存储。这在我创建具有Write权限的 SAS 时有效,但它会在具有权限的情况下引发以下错误Create

ErrorCode: AuthorizationPermissionMismatch

This request is not authorized to perform this operation using this permission

这是预期的行为吗?我想将 SAS 令牌传递给用户并允许他们创建一个 blob,但在创建后不覆盖它。我怎样才能做到这一点?

4

1 回答 1

0

更新:

上传块 Blob 时,您需要写入权限。

在此处输入图像描述

这是文档:

https://docs.microsoft.com/en-us/rest/api/storageservices/create-account-sas#blob-service

原答案:

请确保您已授予创建权限:

在此处输入图像描述

下面是我的代码(C#),它工作正常(我可以创建即使 blob 不存在。):

using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp28
{
    class Program
    {
        static void Main(string[] args)
        {
            string containerName = "test";
            string token = "?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-01-04T09:41:18Z&st=2021-01-04T01:41:18Z&spr=https&sig=UVhS9bPGqWhjKnlrQIMkWHD6Bdfdpym8vgZoQ6W9qDE%3D";
            string sas_uri = "https://0730bowmanwindow.blob.core.windows.net/test?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-01-04T09:41:18Z&st=2021-01-04T01:41:18Z&spr=https&sig=UVhS9bPGqWhjKnlrQIMkWHD6Bdfdpym8vgZoQ6W9qDE%3D";

            BlobServiceClient blobServiceClient = new BlobServiceClient(new Uri(sas_uri));
            
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

            BlobClient blobClient = containerClient.GetBlobClient("20210104.txt");
            byte[] byteArray = Encoding.UTF8.GetBytes("This is a test.20210104");

            MemoryStream stream = new MemoryStream(byteArray);
            blobClient.Upload(stream, true);
        }
    }
}
于 2021-01-04T03:18:30.590 回答