Hello, i periodicaly update my project deps and i upgraded the @azure/storage-blob package.
Was before update
"@azure/identity": "^4.10.2",
"@azure/storage-blob": "^12.27.0",
After update
"@azure/identity": "^4.11.1",
"@azure/storage-blob": "^12.28.0",
My code:
async getSaSToken(blobName: string): Promise<string> {
const { startTime, expirationTime, userDelegationKey } =
await this.getUserDelegationKey(this.THIRTY_MINUTES);
const sasOptions: BlobSASSignatureValues = {
blobName,
containerName: BlobContainerNamesEnum.UPLOADS,
permissions: BlobSASPermissions.parse('r'),
protocol: SASProtocol.Https,
startsOn: startTime,
expiresOn: expirationTime,
};
const sasToken = generateBlobSASQueryParameters(
sasOptions,
userDelegationKey,
this.storageAccountConfig.name,
).toString();
return `${this.blobStorageUrl}/${BlobContainerNamesEnum.UPLOADS}/${blobName}?${sasToken}`;
}
private async getUserDelegationKey(liveDuration: number): Promise<{
startTime: Date;
expirationTime: Date;
userDelegationKey: ServiceGetUserDelegationKeyResponse;
}> {
const NOW = new Date();
const startTime = new Date(NOW.valueOf() - this.TEN_MINUTES);
const expirationTime = new Date(NOW.valueOf() + liveDuration);
const userDelegationKey: ServiceGetUserDelegationKeyResponse =
await this.blobServiceClient
.getUserDelegationKey(startTime, expirationTime)
.catch((error) => {
this.logger.error(error, error.stack);
throw new InternalServerErrorException();
});
console.log(userDelegationKey);
return { startTime, expirationTime, userDelegationKey };
}
Error itself:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at Function.from (node:buffer:322:9)
at new UserDelegationKeyCredential (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/credentials/UserDelegationKeyCredential.ts:37:23)
at generateBlobSASQueryParametersInternal (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:341:35)
at generateBlobSASQueryParameters (/media/vasile/tt/tech-titans/chat-backend/node_modules/@azure/storage-blob/src/sas/BlobSASSignatureValues.ts:320:10)
at BlobStorageService.getSaSToken (/media/vasile/tt/tech-titans/chat-backend/src/core/blob-storage/blob.storage.service.ts:124:52)