
Security News
Feross on TBPN: Socket's Series C and the State of Software Supply Chain Security
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.
astro-cloudflare-media
Advanced tools
Astro integration for managing media uploads to Cloudflare (Stream, R2, Images)
A development-time Astro integration for managing media uploads to Cloudflare (Stream, R2, Images).
/_media for managing all uploadsnpm install astro-cloudflare-media
Add the integration to your astro.config.mjs:
import { defineConfig } from 'astro/config';
import cloudflareMedia from 'astro-cloudflare-media';
export default defineConfig({
integrations: [
cloudflareMedia({
// All config is optional - uses environment variables by default
dashboardRoute: '/_media', // Default dashboard URL
}),
],
});
Create a .env file with your Cloudflare credentials:
# Required
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_API_TOKEN=your_api_token
# Optional - for R2
CLOUDFLARE_R2_BUCKET=podcast-media
CLOUDFLARE_R2_PUBLIC_URL=https://media.yourdomain.com
# Optional - for Images
CLOUDFLARE_IMAGES_HASH=your_delivery_hash
Start your dev server and visit /_media to access the media dashboard:
npm run dev
# Open http://localhost:4321/_media
The dashboard allows you to:
You can also use the API directly in your code:
import { CloudflareClient, StreamApi, ImagesApi } from 'astro-cloudflare-media';
// Create client
const client = new CloudflareClient({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
apiToken: process.env.CLOUDFLARE_API_TOKEN,
});
// Upload video
const streamApi = new StreamApi(client);
const { uploadURL, uid } = await streamApi.createDirectUpload({
maxDurationSeconds: 3600,
metadata: { name: 'My Video' },
});
// Upload image
const imagesApi = new ImagesApi(client);
const image = await imagesApi.upload(file, {
filename: 'cover.jpg',
metadata: { episode: '001' },
});
import { getStreamUrls } from 'astro-cloudflare-media';
const urls = getStreamUrls('your-video-id');
// urls.iframe - Embed URL
// urls.hls - HLS manifest for custom players
// urls.mp4 - Download URL
// urls.thumbnail(0) - Thumbnail at 0 seconds
// urls.gif(0, 5) - Animated GIF from 0-5 seconds
This plugin is designed to work seamlessly with podcast content collections.
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
const mediaSchema = z.object({
audioUrl: z.string(),
audioDuration: z.number(),
audioSize: z.number(),
audioType: z.string().default('audio/mpeg'),
videoUrl: z.string().optional(),
streamVideoId: z.string().optional(),
thumbnail: z.string().optional(),
});
const podcast = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
media: mediaSchema,
draft: z.boolean().default(false),
}),
});
export const collections = { podcast };
---
title: "Episode 1: Getting Started"
description: "Introduction to the podcast"
pubDate: 2025-01-15
media:
audioUrl: "https://r2.yourdomain.com/episodes/001.mp3"
audioDuration: 1847
audioSize: 29552640
streamVideoId: "abc123xyz" # Cloudflare Stream ID
thumbnail: "/thumbnails/001.jpg"
draft: false
---
Show notes content here...
Full TypeScript support with exported types:
import type {
CloudflareMediaConfig,
StreamVideo,
CloudflareImage,
MediaItem,
} from 'astro-cloudflare-media';
MIT
FAQs
Astro integration for managing media uploads to Cloudflare (Stream, R2, Images)
We found that astro-cloudflare-media demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Feross Aboukhadijeh joins TBPN to discuss Socket's $60M Series C, 500%+ ARR growth, AI's impact on open source, and the rise in supply chain attacks.

Security News
OSV withdrew 157 OSV malware reports after automated false positives incorrectly flagged trusted npm and PyPI packages, sending bad records into tools that rely on OSV data.

Research
/Security News
TrapDoor crypto stealer hits 36 malicious packages across npm, PyPI, and Crates.io, targeting crypto, DeFi, AI, and security developers.