服务器未能通过身份验证请求。请参考www-authenticate标头中的信息。

huangapple go评论99阅读模式
英文:

How to fix Server failed to authenticate the request. Please refer to the information in the www-authenticate header

问题

I am currently working on uploading the screenshot of React UI to the Azure blob storage.

But I have some issues when I upload the screenshot image.

Here is my part of codebase.

export const getCapturedImageBlob = async (container) => {
    const screenshot = await html2canvas(container);
    return screenshot;
}

export const uploadImageToBlobStorage = (screenshot, connection_string, container_name, blob_name) => {
    screenshot.toBlob(blob => {
        console.log(blob);
        const blobServiceClient = new BlobServiceClient(connection_string);
        const containerClient = blobServiceClient.getContainerClient(container_name);
        const blobClient = containerClient.getBlockBlobClient(blob_name);

        blobClient.uploadData(blob);
    })
}
const screenshot = await getCapturedImageBlob(document.querySelector("#root"));
    uploadImageToBlobStorage(screenshot, 'https://{Account Name}.blob.core.windows.net', {Container Name}, {Blob Name});

Once I tried to upload the screenshot, I got this error.
服务器未能通过身份验证请求。请参考www-authenticate标头中的信息。

PUT https://{Account Name}.blob.core.windows.net/{Container Name}/{Blob Name}?{Account Key} 401 (Server failed to authenticate the request. Please refer to the information in the www-authenticate header.)
英文:

I am currently working on uploading the screenshot of React UI to the Azure blob storage.

But I have some issues when I upload the screenshot image.

Here is my part of codebase.

./src/captureError.js
export const getCapturedImageBlob = async (container) => {
    const screenshot = await html2canvas(container);
    return screenshot;
}

export const uploadImageToBlobStorage = (screenshot, connection_string, container_name, blob_name) => {
    screenshot.toBlob(blob => {
        console.log(blob);
        const blobServiceClient = new BlobServiceClient(connection_string);
        const containerClient = blobServiceClient.getContainerClient(container_name);
        const blobClient = containerClient.getBlockBlobClient(blob_name);

        blobClient.uploadData(blob);
    })
}
./src/App.js
const screenshot = await getCapturedImageBlob(document.querySelector("#root"));
    uploadImageToBlobStorage(screenshot, 'https://{Account Name}.blob.core.windows.net', {Container Name}, {Blob name});

Once I tried to upload the screenshot, I got this error.
服务器未能通过身份验证请求。请参考www-authenticate标头中的信息。

PUT https://{Account Name}.blob.core.windows.net/{Container Name}/{Blob Name}?{Account Key} 401 (Server failed to authenticate the request. Please refer to the information in the www-authenticate header.)

答案1

得分: 2

谢谢提供错误截图。查看错误详情,似乎您正在使用不正确的请求URL上传 blob。

PUT https://{Account Name}.blob.core.windows.net/{Container Name}/{Blob Name}?{Account Key}

上述语法是不正确的。不应将帐户密钥作为查询字符串传递。如果您使用 SAS 令牌上传您的 blob,语法如下所示:

更多有关 SAS 令牌的信息在这里。请参考提供的示例代码此处此处

英文:

Thanks for the error screenshot. Looking at the error details, it seems like you are uploading the blob using an incorrect request URL.

PUT https://{Account Name}.blob.core.windows.net/{Container Name}/{Blob Name}?{Account Key}

The above syntax is incorrect. Account Key shouldn't be passed as a query string. If you are using the SAS token to upload your blob, the syntax is as shown below:

服务器未能通过身份验证请求。请参考www-authenticate标头中的信息。

More Information about the SAS token is here. Please refer the sample code provided here and here.

答案2

得分: 0

Azure存储只允许经授权的PUT(上传)操作。Azure存储支持的授权方式如下:

  1. 共享密钥(存储帐户密钥)
  2. 共享访问签名(SAS) 令牌。
  3. Azure活动目录(Azure AD)

如果您不想使用SAS令牌,您需要使用AAD RBAC权限或使用SharedKey来在执行PUT操作时访问存储。

示例代码在此处

英文:

The Azure Storage allows only authorized PUT (Upload)operations.

The supported authorizations in Azure storage are mentioned below:

  1. Shared Key (storage account key)
  2. Shared access signature (SAS) token.
  3. Azure Active Directory (Azure AD)

If you don't want to use the SAS token, You need to use AAD RBAC permissions or use SharedKey to access the storage while performing the PUT operation.

Sample code is here.

huangapple
  • 本文由 发表于 2023年4月11日 08:57:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981712.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定