Azure 存储容器的 SAS 令牌失败 403 错误

问题描述 投票:0回答:1

尝试列出存储在 blob 存储容器中的文件。生成 SAS url 并使用以下程序。但出现错误

错误 - 无法获取数据:403

import 'dart:convert';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;

void main() async {
  final String folderURL = 'https://myblobaccount.blob.core.windows.net/azure-webjobs-hosts?sp=r&st=2024-03-22T07:21:47Z&se=2024-03-22T15:21:47Z&sv=2022-11-02&sr=c&sig=Eg%2B04lD3EWLo2wGocU9mqNjKwqKmo04zSCH0Dbsjqlg%3D';//$storageBlobEndpoint/$containerName?$sasToken';

  // Make a request to list the blobs within the folder
  final response = await http.get(Uri.parse(folderURL));
  if (response.statusCode == 200) {
    final List<dynamic> blobs = json.decode(response.body);
    print("Files in the folder:");
    for (var blob in blobs) {
      print(blob['name']);
    }
  } else {
    print('Failed to fetch data: ${response.statusCode}');
  }
}

可能是什么问题?

flutter azure dart azure-blob-storage azure-storage
1个回答
0
投票
Error - Failed to fetch data: 403

即使我尝试使用相同的容器 URL,也会遇到相同的错误。

错误: enter image description here

发生上述错误是由于您发送请求时使用的 URL 不正确。

要列出 blob,您需要使用下面的 URL。

要求:

https://myaccount.blob.core.windows.net/mycontainer?restype=container&comp=list&<Your sas token>

输出: enter image description here

参考:

列出 Blob(REST API)- Azure 存储 |微软学习

© www.soinside.com 2019 - 2024. All rights reserved.