I found the right answer.
The core of the problem is the SAS Token they gave me, was already bound to the container named "abc".
The SAS Token was not an authorization to everything under the domain, the token only authorized me to visit the container "abc".
So when I created the BlobServiceClient object, the "position" (if I can say so) was already under the container 'abc'. Since I'm already in a container, I can't list container
anymore.
When I change the full path and try to connect the root, the token was actually not allowed. Of course the authorization failed.
Conclude:
The SAS token is already bounded to the specific container 'abc', so neither I can list the containers, nor I can visit the domain's root path.
I can only list the data of blobs in the specific container.
The blob-storage package's error message is not very clear.
Here't the code
const { BlobServiceClient } = require("@azure/storage-blob");
const account = "validaccount";
const sas = "sv=xxxx&.......";
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.customdomain.name/abc?${SAS}`);
////====== just change 'list container' code to 'list blobs' code
const containerName = ""; //empty string, since you already in the container.
async function main() {
const containerClient = blobServiceClient.getContainerClient(containerName);
let i = 1;
let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
console.log(`Blob ${i++}: ${blob.name}`);
}
}
main();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…