几天来我一直在尝试使用 Azure Blob 存储 REST API。
我可以连接到资源,列出容器,还可以为任何给定的容器生成 SAS 令牌,没有任何问题。
但是,当我尝试使用为容器生成的 SAS 令牌列出容器内的 Blob 时,现在遇到了问题。
使用我生成的 SAS 令牌,我尝试了以下 curl 命令(取自https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id)
curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list&?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"
其中https://dat3473spa01cfeMtest.blob.core.windows.net
blobServiceUri90480397-91234697-218-test-dir01
是容器名称,并且?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl
是我在上一步中为容器生成的 SAS 令牌。
运行 curl 命令时我收到以下错误消息:
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:d370a92d-301e-0082-34ee-25f845000000
Time:2024-10-24T08:30:24.7319888Z</Message>
<AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
</Error>
我认为问题与我在 curl 命令中指定 SAS 令牌的方式有关,但是从前面提到的网站()上的文档中,https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs?tabs=microsoft-entra-id
我看不出如何正确指定 SAS 令牌,如果这确实是我的 curl 命令的问题。
我也尝试过以下命令:
curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: ?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"
curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: credential=?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"
curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: credentials=?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"
curl -X GET "https://dat3473spa01cfeMtest.blob.core.windows.net/90480397-91234697-218-test-dir01?restype=container&comp=list" -H "x-ms-version: 2025-01-05" -H "x-ms-date: Thu, 24 oct. 2024 08:29:07 GMT" -H "Authorization: token ?sv=2019-02-02&sr=c&sig=QlSozpknsTcR4frUK08%2FrcGaUGY893GzFN1Lyhl74Ao%3D&se=2024-10-24T07%3A50%3A11Z&sp=racwdl"
这些都给出错误:
<Error>
<Code>InvalidAuthenticationInfo</Code>
<Message>Authentication information is not given in the correct format. Check the value of Authorization header.
RequestId:79a74d3f-101e-0071-5bf0-255fd0000000
Time:2024-10-24T08:44:39.7753277Z</Message>
</Error>