components
All repositories: gitoria
1.1 KB
// demo.hl — `/file-upload`: the upload on a page. WHERE THE FILE GOES IS THE APP'S DECISION: the component sends the file through// `emit server saveFile(file)`; this demo keeps it in storage/uploads under a random name (nothing is served back), for one day.parent '../main.hl'import FileUpload from './file-upload.hl'import { writeFile, mkDir, listDir, remove } from 'hl:fs'import { randomBytes } from 'hl:crypto'import { now } from 'hl:time'__title = 'File upload · Hybriel components'View {fileUploadDemo {h1 { "File upload" }p { class = "muted" "Drop a file on the box, or choose one: its name, size and progress show, then it is listed as uploaded." }FileUpload { }p { a { id = "readme" href = "/file-upload/README.md" "README (how to use it)" } }}}on server saveFile(file) {mkDir('storage/uploads')writeFile('storage/uploads/' + now() + '-' + randomBytes(6) + '.bin', file.bytes)for (e of listDir('storage/uploads')) {let stamp = toNumber(e.name.slice(0, e.name.indexOf('-')))if (stamp != null && stamp < now() - 86400000) { remove(e.path) }}return { name = file.name size = file.size }}
Branches
- mainmain branch
Latest commits
- 4b4dabe5State of 2026-09-27, before the move to gitoriamre