const { BlockBlobClient, BlobSASPermissions } = require("@azure/storage-blob");
const blobClient = new BlockBlobClient(
"DefaultEndpointsProtocol=https;AccountName=yyyy;AccountKey=xxxx;EndpointSuffix=core.windows.net",
"test",
"hoge/huga/baz.txt"
);
const expiresOn = new Date();
expiresOn.setMinutes(expiresOn.getMinutes() + 5);
const h = blobClient.generateSasUrl({ expiresOn, permissions: BlobSASPermissions.from({ read: true })}).then((res) => {
console.log(res);
});
Executing this script, which uses Azure JavaScript SDK, outputs
https://yyyy.blob.core.windows.net/test/hoge%2Fhuga%2Fbaz.txt?sv=2024-05-04&se=2024-07-09T03%3A38%3A03Z&sr=b&sp=r&sig=wHPR6FOUyvXWdQafJ%2F8deC1lVH%2Fl0%2Fu4ZGqqLcsJDmU%3D
.
Is this expected behavior? How can I make path to be /test/hoge/huga/baz.txt
?
2
Answers
My colleague investigated further on this. Rationale beind this design is explained in https://github.com/Azure/azure-sdk-for-js/issues/6886#issuecomment-572852591.
According to https://github.com/Azure/azure-sdk-for-js/pull/23461, a fix is to use ContainerClient#getBlobClient.
Yes, it is expected behavior, you can change the expected(decoded) path using below code.
Code:
Output:
I also checked the blob URL is working fine.