Overview
The Azure File storage service offers fully managed file shares in the cloud that are accessible via the SMB protocol. This reference provides details on the REST API, SDK methods, and best practices for working with files and directories.
Authentication & Authorization
All requests to the File service must be authorized. Azure supports Shared Key authentication, Shared Access Signatures (SAS), and Azure AD integration.
Authorization: SharedKey <accountName>:<signature> Authorization: SharedAccessSignature <sv>=<version>...
Operations
| Operation | HTTP Method | URI | Purpose |
|---|---|---|---|
| Create Share | PUT | /<shareName> | Create a new file share |
| Delete Share | DELETE | /<shareName> | Delete an existing share |
| Create Directory | PUT | /<shareName>/<directoryPath> | Create a directory inside a share |
| Delete Directory | DELETE | /<shareName>/<directoryPath> | Delete a directory |
| Create File | PUT | /<shareName>/<directoryPath>/<fileName> | Create an empty file |
| Upload Range | PUT | /<shareName>/<directoryPath>/<fileName>?comp=range | Upload data to a file range |
| Download Range | GET | /<shareName>/<directoryPath>/<fileName>?comp=range | Download a file range |
| Set File Properties | PUT | /<shareName>/<directoryPath>/<fileName>?comp=properties | Set file metadata, attributes |
| Get File Properties | GET | /<shareName>/<directoryPath>/<fileName>?comp=metadata | Retrieve file properties |
| List Files & Directories | GET | /<shareName>/<directoryPath>?restype=directory&comp=list | List contents of a directory |
Code Samples
Creating a File Share (C#)
using Azure.Storage.Files.Shares;
var serviceClient = new ShareServiceClient("");
var shareClient = serviceClient.GetShareClient("myshare");
await shareClient.CreateIfNotExistsAsync();
Uploading a File (Python)
from azure.storage.fileshare import ShareFileClient
file_client = ShareFileClient.from_connection_string(
conn_str="",
share_name="myshare",
file_path="docs/readme.txt")
with open("readme.txt","rb") as data:
file_client.upload_file(data)
Downloading a Range (REST)
GET https://myaccount.file.core.windows.net/myshare/docs/readme.txt?comp=range&range=bytes=0-1023 HTTP/1.1 Authorization: SharedKey myaccount:<signature> x-ms-version: 2023-09-01
Best Practices
- Use SAS tokens for limited-time, scoped access.
- Leverage parallelism when uploading large files (multiple range PUTs).
- Enable SMB encryption for on-premises access.
- Monitor with Azure Monitor metrics:
FileShareCapacity,FileShareTransactions.