|
1 | | -# To be created. |
| 1 | +## Azure Functions Node.js Extensions - Blob |
| 2 | + |
| 3 | +This project provides extensions for working with Azure Blob Storage in Azure Functions using Node.js. It simplifies the integration and interaction with Blob Storage, enabling developers to build scalable and efficient serverless applications. |
| 4 | + |
| 5 | +### Features |
| 6 | + |
| 7 | +- **Blob Trigger**: Automatically trigger Azure Functions when a blob is created or updated in a specified container. |
| 8 | +- **Blob Input Binding**: Read blob content as input to your function. |
| 9 | +- **Cached Client Management**: Optimized client reuse with intelligent caching |
| 10 | +- **Resource Management**: Proper disposal patterns for Azure resource clients |
| 11 | +- **Performance Optimizations**: Reduced overhead for blob operations |
| 12 | + |
| 13 | +### Prerequisites |
| 14 | + |
| 15 | +- [Node.js](https://nodejs.org/) (LTS version recommended) |
| 16 | +- [Azure Functions Core Tools](https://learn.microsoft.com/azure/azure-functions/functions-run-local) |
| 17 | +- An active [Azure subscription](https://azure.microsoft.com/free/) |
| 18 | + |
| 19 | +### Installation |
| 20 | + |
| 21 | +To install the required dependencies, run: |
| 22 | + |
| 23 | +```bash |
| 24 | +npm install @azure/functions-extensions-blob |
| 25 | +``` |
| 26 | + |
| 27 | +### Usage |
| 28 | + |
| 29 | +1. **Set up your Azure Blob Storage account**: |
| 30 | + |
| 31 | + - Create a storage account in the Azure portal. |
| 32 | + - Create a container within the storage account. |
| 33 | + |
| 34 | +2. **Configure your function**: |
| 35 | + |
| 36 | + - Update the `function.json` file to include the appropriate bindings for Blob Storage. |
| 37 | + |
| 38 | +3. **Import and initialize the extension:** |
| 39 | + |
| 40 | +```javascript |
| 41 | +import '@azure/functions-extensions-blob'; // Ensures at the top of the file |
| 42 | +``` |
| 43 | + |
| 44 | +Using in Azure Functions |
| 45 | + |
| 46 | +```javascript |
| 47 | +import "@azure/functions-extensions-blob"; // Ensures side effects run |
| 48 | +import { StorageBlobClient } from "@azure/functions-extensions-blob"; |
| 49 | +import { app, InvocationContext } from "@azure/functions"; |
| 50 | + |
| 51 | +export async function storageBlobTrigger1( |
| 52 | + blobStorageClient: StorageBlobClient, |
| 53 | + context: InvocationContext |
| 54 | +): Promise<void> { |
| 55 | + context.log( |
| 56 | + `Storage blob function processed blob "${context.triggerMetadata.name}"` |
| 57 | + ); |
| 58 | + try { |
| 59 | + // Use the cached client for better performance |
| 60 | + const downloadBlockBlobResponse = |
| 61 | + await blobStorageClient.blobClient.download(); |
| 62 | +// Additional operations... |
| 63 | + |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +app.storageBlob("storageBlobTrigger1", { |
| 68 | + path: "snippets/SomeFolder/{name}", |
| 69 | + connection: "AzureWebJobsStorage", |
| 70 | + sdkBinding: true, //Ensure this is set to true |
| 71 | + handler: storageBlobTrigger1, |
| 72 | +}); |
| 73 | + |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +4. **Run locally**: |
| 78 | + |
| 79 | +- Use the Azure Functions Core Tools to run your function locally: |
| 80 | + `bash |
| 81 | + func start |
| 82 | + ` |
| 83 | + |
| 84 | +4. **Deploy to Azure**: |
| 85 | + |
| 86 | +- Deploy your function to Azure using the following command: |
| 87 | + `bash |
| 88 | + func azure functionapp publish <YourFunctionAppName> |
| 89 | + ` |
| 90 | + |
| 91 | +### Contributing |
| 92 | + |
| 93 | +Contributions are welcome! Please follow the [contribution guidelines](CONTRIBUTING.md) when submitting issues or pull requests. |
| 94 | + |
| 95 | +### License |
| 96 | + |
| 97 | +This project is licensed under the [MIT License](LICENSE). |
| 98 | + |
| 99 | +### Resources |
| 100 | + |
| 101 | +- [Azure Functions Documentation](https://learn.microsoft.com/azure/azure-functions/) |
| 102 | +- [Azure Blob Storage Documentation](https://learn.microsoft.com/azure/storage/blobs/) |
| 103 | +- [Azure SDK for JavaScript](https://learn.microsoft.com/azure/javascript/) |
0 commit comments