Spaces:
Sleeping
Sleeping
File size: 2,462 Bytes
0292484 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | # File Upload Implementation
## Overview
File upload uses **HTTP Resumable Upload** β the reliable, headless method.
## HTTP Resumable Upload
### Implementation
Uses Google's 3-step resumable upload protocol:
1. **Register source intent** (RPC: `o4cbdc`) β get SOURCE_ID
2. **Start upload session** (POST to `/upload/_/`) β get upload URL
3. **Stream file content** β upload URL (memory-efficient streaming)
### Code Structure
- `SourceMixin._register_file_source()` - Step 1: Register and get SOURCE_ID
- `SourceMixin._start_resumable_upload()` - Step 2: Get upload URL
- `SourceMixin._upload_file_streaming()` - Step 3: Stream file content
- `SourceMixin.add_file()` - Public API that orchestrates all 3 steps
### Usage
**Python:**
```python
from notebooklm_tools.core.client import NotebookLMClient
with NotebookLMClient() as client:
result = client.add_file(notebook_id="...", file_path="document.pdf")
# Returns: {"id": "source-id", "title": "document.pdf"}
```
**CLI:**
```bash
nlm source add <notebook-id> --file document.pdf
```
**MCP:**
```python
source_add(notebook_id="...", source_type="file", file_path="/path/to/file.pdf")
```
### Supported File Types
- PDF (`.pdf`)
- Text (`.txt`, `.md`)
- Documents (`.docx`, `.csv`)
- Audio (`.mp3`)
- Video (`.mp4`)
- Images (`.jpg`, `.jpeg`, `.png`)
### Advantages
- β
No Chrome dependency
- β
Works in headless/server environments
- β
Memory-efficient streaming for large files
- β
Faster and more reliable
- β
No browser fingerprinting issues
## Testing
```bash
# Create a test file
echo "Test content" > test.txt
# Upload the file
nlm source add <notebook-id> --file test.txt
# Verify it was added
nlm source list <notebook-id>
```
## Troubleshooting
### "File not found"
- **Cause**: The file path doesn't exist or is inaccessible
- **Fix**: Check the file path spelling and permissions
### "Unsupported file type"
- **Cause**: File extension is not in the supported list
- **Fix**: Convert the file to a supported format
### Upload times out
- **Cause**: Large file or slow connection
- **Fix**: The upload may still complete on the backend; check notebook sources before retrying
---
## Historical Note
A browser-based upload fallback using Chrome automation was previously available (`--browser` flag) but has been removed. NotebookLM's UI now uses the File System Access API which cannot be automated via CDP. The HTTP method is more reliable anyway.
|