Overview
Thedownload action retrieves document files from the server’s file storage and streams them to the client. This action is used by the OnlyOffice Document Server to access documents for editing or viewing.
Endpoint
Query Parameters
Must be set to
download to invoke this actionThe unique identifier of the file to download. The handler searches for files matching the pattern
{fileId}.* in the uploads directory.Request Example
Response
Success Response (200 OK)
When the file is found, the handler returns the file as a binary stream:HTTP status code indicating success
MIME type of the response, set to generic binary stream
Header indicating the file should be downloaded with its original filename:
attachment; filename={filename}The raw file contents
Example Success Response
Error Response (404 Not Found)
When the file is not found or the fileId is invalid:HTTP status code indicating the file was not found
Error message in plain text format
Example Error Response
File Storage Location
Files are stored in the~/App_Data/uploads directory with the naming pattern:
File Resolution Process
- The handler maps the uploads directory:
~/App_Data/uploads - Creates the directory if it doesn’t exist
- Searches for files matching
{fileId}.*pattern - Returns the first matching file
Example File Structure
Error Handling
The download action handles the following error conditions:Missing or Empty fileId
If thefileId parameter is missing, null, or whitespace:
File Not Found
If no file matches the{fileId}.* pattern:
File Exists Check
Even if a matching filename is found, the handler verifies the file exists before streaming:Implementation Details
Source Code Reference
The download action is implemented in:Code Example
Usage in OnlyOffice Document Server
The download action is typically used in the OnlyOffice Document Server configuration as the document URL:Security Considerations
Recommended Security Measures
- Authentication: Verify user identity before allowing downloads
- Authorization: Check if the user has permission to access the specific file
- File ID Validation: Validate that the fileId parameter doesn’t contain path traversal characters
- Rate Limiting: Implement rate limiting to prevent abuse
Example Security Implementation
Related Actions
Callback Action
Handle document updates from OnlyOffice Document Server
Proxy Action
Proxy external document requests