photo
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
servePhoto.ts
https://figleaf--e5907e2ababb11f085f50224a6c84d84.web.val.run
A simple Val Town project that displays a photo on a webpage, updatable via email.
This project consists of two Val Town handlers:
- Email Handler (
photoEmailHandler.ts) - Receives photos via email and stores them - HTTP Handler (
servePhoto.ts) - Serves the current photo on a webpage
Send an email with exactly one image attachment to your Val Town email address. The handler will:
- Validate the image attachment
- Store the image in blob storage
- Keep a history of all uploaded photos
- Send you a confirmation email with upload details
Visit your Val's HTTP endpoint to see:
- The current photo displayed in a clean, centered layout
- A small counter showing which photo number it is (e.g., "This is the 3rd photo.")
- Email-based uploads - No UI needed to update photos
- Upload history - Tracks all photos with metadata (timestamp, sender, filename)
- Photo counter - Displays which upload number the current photo is
- Multiple format support - JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO
- Error handling - Email notifications for upload errors
- Caching - HTTP responses cached for 5 minutes for performance
photo/
├── photoEmailHandler.ts # Email trigger handler
├── servePhoto.ts # HTTP endpoint handler
├── deno.json # Deno configuration
└── README.md # This file
Serves an HTML page displaying the current photo with a counter.
Returns the raw image file with appropriate Content-Type header.
photo- The current photo (binary data)photoMeta- Metadata for the current photo{ contentType: string, extension: string, originalFilename: string, uploadedAt: string, photoNumber: number }photoHistory_{n}- Historical record for each upload{ photoNumber: number, uploadedAt: string, filename: string, contentType: string }
- Attachment count: 1 image
- Response: Confirmation email with upload details
- No images: Error email requesting an image attachment
- Multiple images: Error email requesting exactly one image
- Processing error: Error email with error details
- Deploy both vals to your Val Town account
- Configure
photoEmailHandler.tsas an email trigger - Configure
servePhoto.tsas an HTTP trigger - Email a photo to your Val Town email address
- Visit your HTTP endpoint to see the photo
- Runtime: Deno on Val Town
- Storage: Val Town Blob Storage
- Image formats: Determined by MIME type
- Max photo size: Limited by Val Town blob storage limits
- Cache duration: 5 minutes (300 seconds)
Edit the CSS in servePhoto.ts to change:
- Background color
- Maximum image width (currently 9600px)
- Counter styling and position
Edit the email templates in photoEmailHandler.ts to customize:
- Confirmation message content
- Error message formatting
- Email subjects
MIT