kemalcr/kemal/kemal-upload
Claude Code and agent skill by kemalcr/kemal
- community
Checking that the SKILL.md file is still in the repository.
Handling file uploads and storage in Kemal using body size safety configuration and established project patterns.
Install
npx vskill@latest install kemalcr/kemal/kemal-uploadSKILL.md
The same SKILL.md was published earlier as kemalcr/kemal/kemal-upload.
Kemal File Uploads & Storage
This skill provides expert guidance on implementing file uploads and storage in Kemal, with explicit safety bounds and validation, strictly following patterns from `kemal-by-example/file-upload-storage`.
Version Notes
Kemal.config.max_request_body_size: since Kemal 1.9.Kemal.config.max_multipart_form_field_size: since Kemal 1.11.- Upload tempfile cleanup in
Kemal::InitHandler(runs for every request, including halted filters): since Kemal 1.13.0.
Core Mandates
- Global Size Limit Configuration (Security in Kemal 1.9+ & 1.11+): Set global request and multipart limits in the entrypoint file:
```crystal # Maximum overall request body size (Kemal 1.9+, e.g. 50MB) Kemal.config.max_request_body_size = 50 1024 1024
# Maximum individual multipart form field size (Kemal 1.11+, e.g. 8MB) Kemal.config.max_multipart_form_field_size = 8 1024 1024 ```
- Uploading: Use
env.params.files.has_key?("file")to check for file presence, thenenv.params.files["file"]to access it:
``crystal unless env.params.files.has_key?("file") env.redirect "/files?error=Please+choose+a+file+to+upload." next "" end uploaded_file = env.params.files["file"] ``
- Pre-Validation: Check the size of the upload before storage (
sizeis the byte count written to disk):
```crystal max_size = 50_u64 1024 1024 upload_size = uploaded_file.size || 0_u64
if upload_size > max_size env.redirect "/files?error=File+size+must+be+50MB+or+smaller." next "" end ```
- Extension Validation: Check allowed extensions before processing:
``crystal unless StoredFile.allowed_extension?(original_name) env.redirect "/files?error=Only+images,+PDF,+and+TXT+files+are+allowed." next "" end ``
- Handling Files:
```crystal extension = ::File.extname(original_name).downcase stored_name = "#{Random::Secure.hex(16)}#{extension}" destination = ::File.join(Kemal.config.public_folder, "uploads", stored_name)
uploaded_file.open do |upload| ::File.open(destination, "w") do |file| IO.copy(upload, file) end end ```
- MIME Type Detection: Use a fallback for missing Content-Type headers:
``crystal mime_type = uploaded_file.headers["Content-Type"]? || "application/octet-stream" ``
- File Deletion: Always check existence before deleting:
``crystal ::File.delete(stored_file.storage_path) if ::File.exists?(stored_file.storage_path) ``
Patterns from Source Code
Upload Route (file-upload-storage/src/routes/files.cr)
StoredFile Model with Extension Validation (file-upload-storage/src/models/stored_file.cr)
File Deletion Route
Best Practices
- Configuration: Always configure
Kemal.config.max_request_body_sizeandKemal.config.max_multipart_form_field_sizeglobally to mitigate resource exhaustion / DoS attacks. - Extension Validation: Use a helper like
StoredFile.allowed_extension?(name)to validate extensions (e.g.,.jpg,.png,.pdf,.txt). - Unique Storage Names: Always generate unique filenames using
Random::Secure.hex(16)to prevent collisions. - Cleanup: Always use
::File.delete(path) if ::File.exists?(path)when deleting files. - Early Validation: Check file presence and extension before processing to fail fast.
When to Use
- When implementing file upload features.
- When configuring Kemal to handle larger request bodies safely.
- When managing stored files (e.g., deleting after use).
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/kemal-upload/SKILL.md
Popularity
- Repository stars
- 3,918
- Repository forks
- 205
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kemalcr/kemal/kemal-upload)