Introduction to Azure Storage Files API
The Azure Storage Files API provides a RESTful interface for interacting with Azure File Shares. You can use this API to perform operations such as creating, deleting, and managing file shares, as well as uploading, downloading, and managing files and directories within those shares.
Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol or Network File System (NFS) protocol. This makes it an ideal solution for lift-and-shift scenarios, shared application settings, development and debugging tools, and more.
Key features include:
- Managed file shares accessible via SMB and NFS.
- Mountable on Windows, macOS, and Linux.
- Integration with Azure Active Directory for identity-based authentication.
- Support for file locking, snapshots, and versioning.
This documentation covers the REST API endpoints for managing Azure File Shares.
API Endpoints
File Share Operations
1. Create File Share
Creates a new file share within the specified storage account.
Parameters
Name | Type | Description | Required |
---|---|---|---|
accountName |
String | The name of the storage account. | Yes |
shareName |
String | The name of the file share to create. | Yes |
x-ms-share-quota |
Integer | Specifies the maximum size of the share in GB. | No |
x-ms-share-snapshot |
DateTime | Specifies a file share snapshot to create. | No |
Example (REST):
curl -v -X PUT \
"https://myaccount.file.core.windows.net/fileshares/myshare?restype=share" \
-H "x-ms-date: Mon, 27 Jul 2024 18:30:00 GMT" \
-H "x-ms-version: 2020-02-12" \
-H "Authorization: SharedKey myaccount:xyzabc=" \
-H "x-ms-share-quota: 1024"
2. Delete File Share
Deletes the specified file share.
Parameters
Name | Type | Description | Required |
---|---|---|---|
accountName |
String | The name of the storage account. | Yes |
shareName |
String | The name of the file share to delete. | Yes |
x-ms-delete-snapshots |
String | Specifies whether to delete snapshots along with the share. Allowed values: 'include' or 'only'. | No |
Example (REST):
curl -v -X DELETE \
"https://myaccount.file.core.windows.net/fileshares/myshare?restype=share" \
-H "x-ms-date: Mon, 27 Jul 2024 18:30:00 GMT" \
-H "x-ms-version: 2020-02-12" \
-H "Authorization: SharedKey myaccount:xyzabc="
Directory Operations
1. Create Directory
Creates a new directory within the specified file share.
Parameters
Name | Type | Description | Required |
---|---|---|---|
accountName |
String | The name of the storage account. | Yes |
shareName |
String | The name of the file share. | Yes |
directoryPath |
String | The path of the directory to create. | Yes |
File Operations
1. Upload File
Uploads a file to the specified directory in the file share.
Parameters
Name | Type | Description | Required |
---|---|---|---|
accountName |
String | The name of the storage account. | Yes |
shareName |
String | The name of the file share. | Yes |
filePath |
String | The path of the file to upload. | Yes |
x-ms-content-length |
Integer | The length of the file content in bytes. | Yes |
x-ms-type |
String | Must be 'File'. | Yes |
Example (REST):
curl -v -X PUT \
"https://myaccount.file.core.windows.net/fileshares/myshare/my-directory/my-file.txt?comp=file" \
-H "x-ms-date: Mon, 27 Jul 2024 18:30:00 GMT" \
-H "x-ms-version: 2020-02-12" \
-H "Authorization: SharedKey myaccount:xyzabc=" \
-H "x-ms-content-length: 1024" \
-H "x-ms-type: File" \
--data-binary "@local_file.txt"
Authentication
Requests to the Azure Storage Files API must be authenticated. The primary methods are:
- Shared Key Authentication: Uses your storage account name and access key.
- Shared Access Signature (SAS): Provides delegated access with specific permissions and expiry times.
- Azure Active Directory (Azure AD): For more robust identity management and role-based access control.
The examples above demonstrate Shared Key authentication. For more details on authentication methods, please refer to the Azure Storage Authentication documentation.