MCPcopy Index your code
hub / github.com/simstudioai/sim / getPresignedUrl

Function getPresignedUrl

apps/sim/lib/uploads/providers/blob/client.ts:172–195  ·  view source on GitHub ↗
(key: string, expiresIn = 3600)

Source from the content-addressed store, hash-verified

170 * @returns Presigned URL
171 */
172export 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

Callers 1

client.test.tsFile · 0.90

Calls 4

getBlobServiceClientFunction · 0.85
getAccountCredentialsFunction · 0.85
parseMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected