Images
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.
index.ts
https://flymaster--30c40466c6fb11f0953942dde27851f2.web.val.run
A minimal image hosting service that displays the last 4 uploaded images.
The application is fully functional with images displaying correctly on the home page.
- / - View the last 4 uploaded images (newest first)
- /add - Upload form for new images (no navigation links to this page)
- Automatic cleanup: images are deleted when there are 4 newer images
- Mobile and desktop friendly
- No frontend JavaScript required
- File size limit: 10MB per image
- Supports common image formats (JPEG, PNG, GIF, WebP)
- Built with Hono framework
- Uses SQLite for metadata storage (filename, content type, file size, upload date)
- Uses Val Town Blob storage for image files (stored as base64)
- Images are automatically cleaned up when more than 4 are uploaded
- Responsive design with CSS Grid and Flexbox
- Server-side rendering with no client-side JavaScript
- Upload functionality available but not linked from the UI
- Fixed base64 encoding/decoding for proper image handling
backend/index.ts- Main application entry point (HTTP trigger)backend/database/migrations.ts- Database schema initializationbackend/database/queries.ts- Database operations and image managementfrontend/style.css- Responsive CSS styling
- Visit the root URL to see uploaded images
- The
/addendpoint provides upload functionality but is not linked from the main interface - Images can be uploaded by directly accessing
/add - Only the 4 most recent images are kept; older images are automatically deleted
GET /- Home page with image gallery (no upload links)GET /add- Upload form page (no navigation links)POST /add- Handle image upload (multipart/form-data)GET /image/:blobKey- Serve individual images with proper content typesGET /frontend/style.css- CSS stylesheet
- Fixed base64 encoding for large images using chunked processing
- Fixed blob data retrieval to handle Response objects correctly
- Improved error handling for image serving
- Removed debug endpoints for production use