Stream File from Drive
Endpoint
Path Parameters
Google Drive file ID (10+ alphanumeric characters)Must match pattern:
[A-Za-z0-9_-]{10,}Request Headers
Request a byte range from the fileFormat:
bytes=start-endExamples:bytes=0-1023- First 1KBbytes=1024-- From byte 1024 to endbytes=-1024- Last 1KB
Response Headers
MIME type from Google Drive (e.g.,
video/mp4, application/pdf, image/png)Size of the response in bytes (full file or range)
Byte range being returned (only for range requests)Format:
bytes start-end/totalExample: bytes 0-1023/5242880Always returns
bytes to indicate range request supportFor video files:
public, max-age=3600For other files: No cache control headerSet for localhost origins only
Response Status Codes
| Code | Meaning |
|---|---|
200 | Full file content returned |
206 | Partial content (range request) |
400 | Invalid file ID format |
416 | Range not satisfiable |
502 | Drive API error |
503 | Drive service not available |
Example: Full File Request
RequestExample: Range Request
RequestPerformance Metrics
The server logs streaming metrics for requests taking >0.5 seconds:Chunk size is optimized at 1MB to reduce overhead and improve A/V sync during video playback.
Stream Compatible Video
Endpoint
- Downloads the file from Drive
- Processes it through ffmpeg
- Outputs browser-compatible MP4 with fragmented structure
Path Parameters
Google Drive file ID for a video file
ffmpeg Processing
The server applies these ffmpeg settings: Default Mode (Copy)- Video codec: Copy original stream (no re-encoding)
- Audio codec: AAC, 48kHz, resampled
- Container: Fragmented MP4 for progressive streaming
PLATZI_COMPAT_FORCE_REENCODE=1 to force video re-encoding:
- Video codec: H.264 (libx264), veryfast preset, yuv420p
- Audio codec: AAC, 48kHz, resampled
- Container: Fragmented MP4
Response Headers
Always
video/mp4Always
none (range requests not supported on transcoded stream)no-store, max-age=0 (transcoded content not cached)Response Status Codes
| Code | Meaning |
|---|---|
200 | Streaming in progress |
400 | Invalid file ID |
502 | ffmpeg processing failed |
503 | ffmpeg or Drive service not available |
Example Response
Requestffmpeg Command
The server constructs this ffmpeg command:Performance Metrics
The server logs compatibility stream statistics:Compatibility Stream Stats
Get real-time statistics via/api/health:
MIME Type Detection
MIME types are determined by Google Drive’s file metadata:Video Files
video/mp4- MP4 videovideo/quicktime- MOV videovideo/x-matroska- MKV videovideo/webm- WebM video
Document Files
application/pdf- PDF documentsapplication/vnd.google-apps.presentation- Google Slidesapplication/vnd.google-apps.document- Google Docs
Image Files
image/png- PNG imagesimage/jpeg- JPEG imagesimage/webp- WebP images
Default
application/octet-stream- Unknown file types
Range Request Support
Video Seeking
Range requests enable efficient video seeking in HTML5 video players:Progressive Download
Range requests allow downloading large files in chunks:Validation
Range header validation: ✅ Valid formats:bytes=0-1023bytes=1024-bytes=-1024
bytes=0-100,200-300(multi-range)items=0-100(wrong unit)bytes=abc-def(non-numeric)
Error Handling
Invalid File ID
RequestDrive Service Unavailable
RequestLocal File Reference (Deprecated)
RequestRange Not Satisfiable
Requestffmpeg Not Available
RequestConfiguration
Environment Variables
Path to service account JSON file
Service account JSON as string (alternative to file)
Path to ffmpeg executable (auto-detected if not set)
Set to
1 to force video re-encoding (default: 0)ffmpeg Detection
The server searches for ffmpeg in this order:FFMPEG_PATHenvironment variableffmpegin system PATH- Windows:
C:\Program Files\ffmpeg\bin\ffmpeg.exe - Windows:
C:\ffmpeg\bin\ffmpeg.exe
Best Practices
Caching Strategy
The server sets cache headers for video files:Bandwidth Optimization
- Use range requests to download only needed portions
- Videos are streamed in 1MB chunks for optimal A/V sync
- Monitor streaming speed in server logs
Next Steps
Course APIs
Get file IDs from course catalog
Progress API
Save video playback positions
Configuration
Configure Drive service account