gpt4 book ai didi

azure - 通过 SAS URI 访问 blob 时出现 "Authentication failed"错误

转载 作者:行者123 更新时间:2023-12-03 06:47:39 25 4
gpt4 key购买 nike

我和我的团队正在使用 NextJS 开发一个 Web 应用程序,最近我们一直在实现 Azure Blob 存储来进行文件上传和显示。我目前正在研究前端的图像显示。为此,我使用包含以下参数的 sasOptions 对象的 generateBlobSASQueryParameters 函数生成 SAS token :

  • 容器名称
  • Blob 名称
  • startsOn(日期对象)
  • expiresOn(日期对象)
  • 权限:BlobSASPermissions.parse("racwdt")

之后,我使用指定的 blob 名称和新生成的 SAS token 生成 SAS URI。但是,当我尝试访问 sas URI 时,我遇到了错误:

Server failed to authenticate the request. Make sure the value ofAuthorization header is formed correctly including the signature.RequestId:SOME_REQUEST_IDTime:2022-10-03T13:49:24.2788454ZSignature fields not well formed.The signature:

https://mystorageaccount.blob.core.windows.net/images/example.png?sv=2021-06-08&ss=bfqt&srt=sco&sp=rwdlacupiytfx&se=2022-11-22T20:45:23Z&st=2022-10-03T11:45:23Z&spr=https&sig=ECjnJEvZCOPhvuOgCsGBMIwone7VmsiJQopVNyb4yB0%3D?sv=2021-06-08&st=2022-10-06T06%3A24%3A12Z&se=2022-10-06T06%3A34%3A12Z&sr=b&sp=racwdt&sig=ioMMCIFo0eXC%2BTZ9yDZB9D5JHz%2F%2BUyMMFqTPEG0QSqg%3D

以下是无法验证的 URL 的参数:

sv=2021-06-08
ss=bfqt
srt=sco
sp=rwdlacupiytfx
se=2022-11-22T20:45:23Z
st=2022-10-03T11:45:23Z
spr=https
sig=ECjnJEvZCOPhvuOgCsGBMIwone7VmsiJQop

生成 SAS URI 时我可以做些什么或注意什么以使其正常工作吗?

注意:通过单击 blob 上的“生成 SAS token 和 URL”按钮手动生成 SAS URL 时,我可以通过将图像复制到浏览器中的 url 字段来访问图像

最佳答案

正如 @Gaurav_Mantri 所建议的,SAS token 在我获得的 SAS URL 中出现了两次。

产生错误 URL 的代码:

 const sasToken = generateBlobSASQueryParameters(
sasOptions,
sharedKeyCredential
).toString();

const blobSasUri = `${
containerClient.getBlockBlobClient(blobName).url
}?${sasToken}`;

在我看来,我已经为特定 blob 生成了 SAS token ,然后使用获取其 url

containerClient.getBlockBlobClient(blobName).url

我已经获得了完整 Blob URL(其中已包含 SAS token )。之后,我再次连接生成的 SAS URL,因此得到了错误的 URL。

修复:

const sasToken = generateBlobSASQueryParameters(
sasOptions,
sharedKeyCredential
).toString(); // For generating the SAS token

const blobURL = containerClient.getBlockBlobClient(blobName).url;
// Afterwards, getting the full blob URL (with the new SAS token already concatinated to it)

关于azure - 通过 SAS URI 访问 blob 时出现 "Authentication failed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73969243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com