【问题标题】:Unable to upload to azure storage with a SAS Token from flutter无法使用颤振的 SAS 令牌上传到 Azure 存储
【发布时间】:2023-03-31 22:25:01
【问题描述】:

我正在尝试使用 SAS 令牌将文件/数据上传到 Azure 存储。 我可以使用以下方法在没有 SAS 令牌的情况下成功实现这一目标

  sendToBlob (Uint8List bytes)async {
    var storage = AzureStorage.parse('DefaultEndpointsProtocol=https;AccountName=#;AccountKey=#==;EndpointSuffix=core.windows.net');
    await storage.putBlob('/test/2.txt',bodyBytes: bytes);
  }

当我生成一个 SAS 令牌并使用以下格式编写的连接字符串时,我收到一个解析错误

"BlobEndpoint=https://#.blob.core.windows.net/;QueueEndpoint=https://#.queue.core.windows.net/;FileEndpoint=https://#.file.core.windows.net/;TableEndpoint=https://#.table.core.windows.net/;SharedAccessSignature=sv=#"

尝试发送不带连接字符串的put请求,我的方法如下:

  uploadtoAzure(String sas)async{
    try {
      var url = 'https://#.blob.core.windows.net/test/4.txt?'+sas;
      Map<String, String> headers = ({"x-ms-blob-type": "BlockBlob"});
      final response = await http.put(
          url,
          headers: headers,
          body: 'hi'
      );
      print(response.statusCode);
    } on DioError catch (e) {
      if(e.response.statusCode == 404){
        print(e.message);
      }else{
        print(e.message);
      }
    }
  }

知道我是我要上传到的存储帐户的所有者和存储 Blob 数据贡献者,并且 SAS 令牌未过期,这会导致 403 AuthorizationPermissionMismatch 错误。 p>

¿<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthorizationPermissionMismatch</Code><Message>This request is not authorized to perform this operation using this permission.
RequestId:bc7f5bb4-c01e-0066-0459-9a6d45000000
Time:2020-10-04T14:16:54.7302685Z</Message></Error>

有没有一种方法可以使用带有 SAS 令牌的连接字符串将数据从颤振上传到天蓝色?我该如何解决这个问题?

感谢任何帮助。

【问题讨论】:

    标签: azure flutter dart connection-string


    【解决方案1】:

    由于我们的 Azure 函数正在生成用户委托 SAS 令牌,因此我们使用 Azure 上的注册应用作为服务主体。

    通过将Storage Blob Data Contributor以及Storage Blob Delegator角色分配给服务主体以适应添加文件,解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 2021-03-07
      • 2022-01-17
      • 2021-04-03
      • 2021-04-07
      • 2022-07-19
      • 1970-01-01
      相关资源
      最近更新 更多