This implementation provides secure access to translated documents stored in private Azure Blob Storage using 5-minute expiring SAS (Shared Access Signature) tokens.
- User uploads document for translation
- Document gets translated and stored in Azure Blob Storage (private container)
- Backend generates a 5-minute SAS URL for the blob
- Frontend receives the SAS URL directly in the translation response
- User can download directly from Azure Storage using the temporary SAS URL
GenerateDocumentSasUrlAsync(): Creates 5-minute SAS tokens for blob access- Uses
BlobSasBuilderwith read-only permissions - Validates blob existence before generating SAS
- Comprehensive logging and error handling
- Document translation endpoint now returns SAS URL directly
- New
/api/translation/sas/{documentId}endpoint for on-demand SAS generation - Proper error handling for missing documents and invalid IDs
- Direct download links using SAS URLs
- No need for custom download methods - browser handles it natively
- Shows expiration warning to users
- Blob container uses
PublicAccessType.None - No public access to any files
- SAS tokens expire in exactly 5 minutes
- Read-only permissions
- Cannot be renewed without server interaction
- SAS URLs only generated through authenticated API calls
- Document ownership validated before SAS generation
- Comprehensive logging of all SAS generation and access
- Document access tracking
Response:
{
"translatedDocumentUrl": "https://storage.blob.core.windows.net/translated/blob-name?sp=r&st=...&se=...&sr=b&sig=...",
"originalFileName": "document.pdf",
"fromLanguage": "en",
"toLanguage": "es"
}Response:
{
"sasUrl": "https://storage.blob.core.windows.net/translated/blob-name?sp=r&st=...&se=...&sr=b&sig=...",
"expiresInMinutes": 5
}- Connection string must be configured in
appsettings.json - Storage account must support SAS token generation
- Recommend using Standard_LRS tier for cost efficiency
{
"DocumentTranslation": {
"StorageConnectionString": "DefaultEndpointsProtocol=https;AccountName=yourstorageaccount;AccountKey=yourkey;EndpointSuffix=core.windows.net"
}
}- Direct downloads from Azure CDN edge locations
- No server bandwidth usage for file transfers
- Faster download speeds for users worldwide
- No permanent public URLs
- Time-limited access prevents link sharing abuse
- Server maintains full control over access
- Reduced server resource usage
- Lower bandwidth costs
- Azure Storage is more cost-effective than server storage
- Downloads don't impact server performance
- Azure Storage handles high concurrent downloads
- Global CDN distribution
Use the provided test files:
test-sas.html- Test SAS URL generationtest-download.html- Test legacy download functionality
Monitor these metrics:
- SAS token generation frequency
- Failed SAS generations (indicates missing documents)
- Download success rates
- Token expiration warnings
The implementation handles:
- Missing documents (404)
- Expired SAS tokens (automatically handled by Azure)
- Storage connectivity issues (falls back gracefully)
- Invalid document IDs (400 Bad Request)
Consider implementing:
- Configurable SAS expiration times
- User-specific access controls
- Download analytics and reporting
- Automatic cleanup of expired documents