upload_and_attach_file_to_page
Upload files to Notion and attach them to specific pages, generating temporary download URLs with file metadata for sharing and access.
Instructions
Upload a file to Notion and attach it to a specific page, returning download URL.
This function performs the complete workflow:
1. Upload file to Notion
2. Create file block and attach to specified page
3. Extract and return download URL with metadata
Args:
file_path: Path to the file to upload
page_id: Notion page ID to attach the file to (with or without dashes)
notion_token: Notion API token for authentication (optional if NOTION_API_TOKEN env var is set)
file_name: Optional custom filename (defaults to original filename)
caption: Optional caption for the file block
Returns:
Dictionary containing:
- file_upload_id: The uploaded file ID
- file_block_id: The created file block ID
- download_url: Temporary download URL (expires in 1 hour)
- expiry_time: ISO timestamp when download URL expires
- filename: Name of the file
- content_type: MIME type of the file
- file_size: Size of the file in bytes
Raises:
Exception: If file doesn't exist, exceeds size limit, or API call fails
Example:
result = await upload_and_attach_file_to_page(
"document.pdf",
"2785bbc0e5c281f48dfae9a48f53f6a6",
notion_token="ntn_xxx"
)
download_url = result["download_url"]
Input Schema
Name | Required | Description | Default |
---|---|---|---|
caption | No | ||
file_name | No | ||
file_path | Yes | ||
notion_token | No | ||
page_id | Yes |
Input Schema (JSON Schema)
{
"properties": {
"caption": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Caption"
},
"file_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "File Name"
},
"file_path": {
"title": "File Path",
"type": "string"
},
"notion_token": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Notion Token"
},
"page_id": {
"title": "Page Id",
"type": "string"
}
},
"required": [
"file_path",
"page_id"
],
"type": "object"
}