(key: string, expiresIn = 3600)
| 170 | * @returns Presigned URL |
| 171 | */ |
| 172 | export async function getPresignedUrl(key: string, expiresIn = 3600) { |
| 173 | const { BlobSASPermissions, generateBlobSASQueryParameters, StorageSharedKeyCredential } = |
| 174 | await import('@azure/storage-blob') |
| 175 | const blobServiceClient = await getBlobServiceClient() |
| 176 | const containerClient = blobServiceClient.getContainerClient(BLOB_CONFIG.containerName) |
| 177 | const blockBlobClient = containerClient.getBlockBlobClient(key) |
| 178 | |
| 179 | const { accountName, accountKey } = getAccountCredentials() |
| 180 | |
| 181 | const sasOptions = { |
| 182 | containerName: BLOB_CONFIG.containerName, |
| 183 | blobName: key, |
| 184 | permissions: BlobSASPermissions.parse('r'), // Read permission |
| 185 | startsOn: new Date(), |
| 186 | expiresOn: new Date(Date.now() + expiresIn * 1000), |
| 187 | } |
| 188 | |
| 189 | const sasToken = generateBlobSASQueryParameters( |
| 190 | sasOptions, |
| 191 | new StorageSharedKeyCredential(accountName, accountKey) |
| 192 | ).toString() |
| 193 | |
| 194 | return `${blockBlobClient.url}?${sasToken}` |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Generate a presigned URL for direct file access with custom container |
no test coverage detected