英文:
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.
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.
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:
More Information about the SAS token is here. Please refer the sample code provided here and here.
答案2
得分: 0
Azure存储只允许经授权的PUT(上传)操作。Azure存储支持的授权方式如下:
如果您不想使用SAS令牌,您需要使用AAD RBAC权限或使用SharedKey来在执行PUT操作时访问存储。
示例代码在此处。
英文:
The Azure Storage allows only authorized PUT (Upload)operations.
The supported authorizations in Azure storage are mentioned below:
- Shared Key (storage account key)
- Shared access signature (SAS) token.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论