Module azure.storage.files

ballerinax/azure.storage.files Ballerina library

0.9.0

Overview

Azure Files offers fully managed file shares in the cloud, accessible via the industry-standard SMB and NFS protocols and a REST API.

The Azure Files connector offers APIs to connect to Azure Files and manage shares and the directories and files within them, covering uploads, downloads, copies, renames, byte ranges, snapshots, leases, and SAS token generation. It also provides a polling Listener that turns files arriving on a share into service events.

Key Features

  • Share-scoped Client for directory and file operations, transfers, copies, and byte ranges
  • Account-level AdminClient for creating, listing, deleting, and restoring shares
  • Polling Listener that routes files arriving on a watched path to raw, typed, or streaming content handlers, with an optional onError notification handler
  • Share snapshots, leases, access policies, SMB handles, and NFS links
  • Authentication with shared key, SAS tokens, connection strings, and Microsoft Entra ID
  • GraalVM compatible for native image builds

Setup guide

To use the Azure Files connector, you must have an Azure subscription and an Azure storage account. If you do not have an Azure account, you can sign up for one here.

Step 1: Create a storage account

  1. Sign in to the Azure portal, search for Storage accounts, and open it.

  2. Click + Create.

    Create a storage account

  3. On the Basics tab, select a subscription and resource group, provide a globally unique storage account name, and pick a region. The Standard performance tier is sufficient for SMB file shares; choose Premium with the File shares account type only if you need provisioned performance or NFS.

    Storage account basics

  4. Click Review + create, then Create, and wait for the deployment to complete. For the full set of options, see the Azure documentation.

Step 2: Create a file share

  1. Open the deployed storage account and navigate to Data storage > File shares.

  2. Click + File share, provide a name, and click Create. The share name is what you pass to the connector's Client at initialization. For details, see the Azure Files documentation.

    Create a file share

Step 3: Obtain the credentials

  1. In the storage account, navigate to Security + networking > Access keys.

  2. Click Show next to key1, then copy the storage account name and the key value. These two values are the accountName and accountKey the connector's shared key authentication uses.

    Copy the access key

The connector also accepts a SAS token or SAS URL (generated under Security + networking > Shared access signature), a connection string (shown alongside each access key), and Microsoft Entra ID credentials.

Generate a SAS token

Quickstart

To use the azure.storage.files connector in your Ballerina application, modify the .bal file as follows:

Step 1: Import the module

Copy
import ballerinax/azure.storage.files;

Step 2: Instantiate a new connector

A Client is bound to a single file share. Provide the credentials through configurable variables:

Copy
configurable string accountName = ?;
configurable string accountKey = ?;

files:Client fileClient = check new ("reports", auth = {accountName, accountKey});

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Upload a file

Copy
check fileClient->uploadFile("./local/q1.pdf", "/reports/q1.pdf");

Get the properties of a file

Copy
files:FileProperties props = check fileClient->getFileProperties("/reports/q1.pdf");

Manage shares

Copy
files:AdminClient admin = check new (auth = {accountName, accountKey});
check admin->createShare("reports");

Step 4: Run the Ballerina application

Save the changes and run the Ballerina application using the following command.

Copy
bal run

Examples

The azure.storage.files connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering use cases like backing up a folder to a share, handing out a time-limited file link, and processing files dropped into a share folder.

  1. File backup - Back up a local folder to a file share and restore a file from it.
  2. Share handout - Upload a report and generate a time-limited, read-only SAS URL to share with a third party.
  3. Drop folder processor - Watch a folder on a share with the listener and process each dropped file, deleting JSON files and moving the rest into a processed folder.

Import

import ballerinax/azure.storage.files;Copy

Other versions

Metadata

Released date: 19 days ago

Version: 0.9.0

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 9

Current verison: 9


Weekly downloads


Source repository


Keywords

Type/Connector

Area/Storage & File Management

Cost/Paid

Vendor/Microsoft


Contributors