-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-azure): expose storage client (#7069)
Expose the storage client for re-use. ```ts import { getStorageClient } from '@payloadcms/storage-azure' import { getPayload } from 'payload' const awaitedConfig = await importConfig('./config.ts') const payload = await getPayload({ config: awaitedConfig }) // Get internal azure blob storage client const storageClient = getStorageClient({ connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING, containerName: process.env.AZURE_STORAGE_CONTAINER_NAME, }) ```
- Loading branch information
Showing
4 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ContainerClient } from '@azure/storage-blob' | ||
|
||
import { BlobServiceClient } from '@azure/storage-blob' | ||
|
||
import type { AzureStorageOptions } from '../index.js' | ||
|
||
let storageClient: ContainerClient | null = null | ||
|
||
export function getStorageClient( | ||
options: Pick<AzureStorageOptions, 'connectionString' | 'containerName'>, | ||
): ContainerClient { | ||
if (storageClient) return storageClient | ||
|
||
const { connectionString, containerName } = options | ||
|
||
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString) | ||
storageClient = blobServiceClient.getContainerClient(containerName) | ||
return storageClient | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters