Slice · AI prompt
Upload + URL resolver behind a storage adapter. localStorage demo, swap to Convex/S3.
# Install `file-upload` — File Upload — pluggable upload + URL resolver with storage-adapter contract
> Upload + URL resolver behind a storage adapter. localStorage demo, swap to Convex/S3.
📚 Knowledge base : https://resource.rahmanef.com/llms.txt
📦 Slice detail : https://resource.rahmanef.com/slices/file-upload
🧠 JSON catalog : https://resource.rahmanef.com/api/knowledge?slice=file-upload
🔗 Source : https://github.com/rahmanef63/resource-site/tree/main/frontend/slices/file-upload
## 1. Install
```bash
npx rahman-resources add file-upload
# alias: npx rr add file-upload
```
The CLI copies `frontend/slices/file-upload/` into your project + augments `.env.example` + installs npm deps automatically. Run it from your project root.
## 2. What it ships
- shadcn primitives: `button`
## 3. Wire it up
Run `npx rr add file-upload`. Wrap your tree with `<FilesAdapterProvider adapter={...}>` — pass `useLocalStorageFilesAdapter()` for a quick demo or implement `FilesAdapter` (upload + remove + useUrl) against your backend. Then drop `<FileUploadButton onUploaded={...}>` anywhere; pair with `<FileChip fileRef={...}>` for rendered chips. Hooks: `useFileUpload()` returns `{upload, uploading, progress, removeFromStorage}`; `useFileUrl(storageId)` resolves to a fetchable URL (Convex adapter uses useQuery for live invalidation; demo reads localStorage synchronously). To wire S3: implement the FilesAdapter interface with presigned URLs + DELETE; the slice doesn't care which backend you pick.
## Rules of engagement
- shadcn-only UI primitives. No raw `<button>` / `<dialog>` / native date or file inputs.
- 200-line hard cap per source file (extract neighbours when over).
- All Convex queries hit an index (`.withIndex(...)`); never bare `.collect()`.
- Public mutations/queries declare `args:` validators + authz.
- Full ruleset: https://resource.rahmanef.com/best-practice
The agent will fetch /llms.txt for the full ruleset and use /api/knowledge for the JSON catalog.