This comprehensive guide will walk you through setting up and deploying your video streaming platform with Cloudflare Stream.
- Prerequisites
- Cloudflare Stream Setup
- Project Configuration
- Video Upload
- Local Development
- Deployment
- Troubleshooting
Before you begin, ensure you have:
- ✅ A modern web browser (Chrome, Firefox, Safari, or Edge)
- ✅ A code editor (VS Code, Sublime Text, etc.)
- ✅ Basic knowledge of HTML, CSS, and JavaScript
- ✅ A Cloudflare account (free tier available)
- ✅ (Optional) A local web server for development
- Go to https://dash.cloudflare.com/sign-up
- Sign up for a free account
- Verify your email address
- Log in to your Cloudflare dashboard
- Navigate to Stream from the left sidebar
- Click "Enable Stream" if not already enabled
- Note: Cloudflare Stream pricing starts at $1 per 1,000 minutes of video stored and $1 per 1,000 minutes delivered
- In the Cloudflare dashboard, go to Stream
- Your Account ID is displayed in the URL bar or on the Stream page
- Copy this ID - you'll need it for configuration
- Click on your profile icon (top right) → My Profile
- Select API Tokens from the left menu
- Click "Create Token"
- Choose "Create Custom Token"
- Configure the token:
- Token name:
Video Streaming Integration - Permissions:
- Account → Stream → Read
- (Optional) Account → Stream → Edit (if you want to upload via API)
- Account Resources: Include → Your Account
- Token name:
- Click "Continue to summary" → "Create Token"
- IMPORTANT: Copy your token immediately! You won't be able to see it again
# Clone the repository (if using git)
git clone <your-repo-url>
cd Video-Streaming-Integration
# Or simply download and extract the ZIP file- Navigate to the
jsfolder in the project - Copy
config.example.jstoconfig.js:cp js/config.example.js js/config.js
- Open
js/config.jsin your code editor - Replace the placeholder values:
const CONFIG = { ACCOUNT_ID: 'your-actual-account-id-here', API_TOKEN: 'your-actual-api-token-here', // ... rest of config };
The config.js file is already in .gitignore to prevent accidentally committing your credentials. Never commit this file to version control!
- Go to your Cloudflare dashboard → Stream
- Click "Upload" button
- Select your video file(s)
- Wait for upload and processing to complete
- Once processed, click on the video to get its Video ID
- Copy the Video ID for use in your config
// Example using fetch API
async function uploadVideo(file) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/stream`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${API_TOKEN}`
},
body: formData
}
);
const data = await response.json();
console.log('Video ID:', data.result.uid);
}For large files, use TUS resumable uploads:
// Using tus-js-client
const upload = new tus.Upload(file, {
endpoint: `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/stream`,
headers: {
'Authorization': `Bearer ${API_TOKEN}`
},
chunkSize: 52428800, // 50 MB
onError: function(error) {
console.error('Upload failed:', error);
},
onSuccess: function() {
console.log('Upload complete!');
}
});
upload.start();After uploading videos, update your config.js:
DEMO_VIDEOS: [
{
id: 'actual-video-id-1',
title: 'Your Video Title',
description: 'Your video description',
thumbnail: 'https://customer-...'
},
// Add more videos...
]# Python 3
python -m http.server 8000
# Python 2
python -m SimpleHTTPServer 8000Then open: http://localhost:8000
# Install http-server globally
npm install -g http-server
# Run server
http-server -p 8000
# Or use live-server for auto-reload
npm install -g live-server
live-server- Install "Live Server" extension in VS Code
- Right-click on
index.html - Select "Open with Live Server"
- Open
index.htmlin your browser - Navigate to the video player page
- Check browser console for any errors
- Verify videos load in the playlist
- Test play/pause, seeking, and other controls
- Push your code to GitHub
- Go to Cloudflare dashboard → Pages
- Click "Create a project"
- Connect your GitHub repository
- Configure build settings:
- Build command: (leave empty)
- Build output directory:
/
- Add environment variables (if needed)
- Click "Save and Deploy"
Your site will be deployed to: https://your-project.pages.dev
- Push your code to GitHub
- Go to https://netlify.com
- Click "New site from Git"
- Select your repository
- Configure:
- Build command: (leave empty)
- Publish directory:
/
- Click "Deploy site"
# Install Vercel CLI
npm install -g vercel
# Deploy
vercel- Push your code to GitHub
- Go to repository Settings → Pages
- Select branch to deploy (e.g.,
main) - Select root folder
/ - Click "Save"
Your site will be available at: https://username.github.io/repository-name
Problem: Videos don't appear in the playlist or won't play.
Solutions:
- Check browser console for errors
- Verify your API credentials in
config.js - Ensure Video IDs are correct
- Check CORS settings in Cloudflare
- Verify your Cloudflare Stream subscription is active
Problem: 401 or 403 errors in console.
Solutions:
- Regenerate your API token
- Verify token has correct permissions (Stream:Read)
- Check Account ID is correct
- Ensure token hasn't expired
Problem: Play/pause or other controls don't respond.
Solutions:
- Check browser console for JavaScript errors
- Ensure all JS files are loaded correctly
- Try in a different browser
- Clear browser cache
- Check for JavaScript conflicts
Problem: Page looks broken or unstyled.
Solutions:
- Verify all CSS files are loading
- Check file paths are correct
- Clear browser cache
- Check browser developer tools for CSS errors
Problem: Cross-Origin Resource Sharing (CORS) errors.
Solutions:
- Serve the site via HTTP server (not file://)
- Configure CORS in Cloudflare Stream settings
- Use signed URLs for restricted content
Problem: Site doesn't display correctly on mobile.
Solutions:
- Check viewport meta tag is present
- Test on multiple devices
- Use browser developer tools' device emulation
- Check for fixed-width elements
To use a custom domain with Cloudflare Pages:
- Add your domain in Cloudflare Pages settings
- Update DNS records
- Enable HTTPS (automatic with Cloudflare)
Track video engagement:
// Get analytics for a video
const analytics = await api.getVideoAnalytics('video-id');
console.log(analytics);For private content, use signed URLs:
// Generate signed URL (requires API implementation)
const signedUrl = await api.getSignedUrl('video-id', {
exp: Date.now() + 3600000 // 1 hour
});Add subtitles via Cloudflare dashboard:
- Go to video details
- Click "Captions"
- Upload WebVTT file
- Enable in player configuration
- Use WebP format for thumbnails
- Lazy load playlist images
- Use Cloudflare Image Resizing
- Minify CSS and JavaScript in production
- Enable gzip/brotli compression
- Use CDN for static assets
- Set appropriate cache headers
- Use Cloudflare's caching rules
- Implement service workers for offline support
- Never commit API credentials to version control
- Use environment variables for sensitive data
- Implement rate limiting for API calls
- Use signed URLs for protected content
- Enable HTTPS everywhere
- Sanitize user inputs if adding comments/features
- Keep dependencies updated
After completing the basic setup:
- ✅ Customize the theme and colors
- ✅ Add your own branding
- ✅ Implement user authentication (if needed)
- ✅ Add commenting system
- ✅ Integrate analytics (Google Analytics, etc.)
- ✅ Create admin panel for video management
- ✅ Add search functionality
- ✅ Implement playlists and categories
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit issues or pull requests.
Happy Streaming! 🎥
For questions or issues, please open an issue on GitHub or contact support.