Migrate remaining footnote-style collection access in examples, public/structure, and ext/lib smokes to [key](base); teach link-index in structure pages and use bracket calls in the cafe journal example. Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
1.8 KiB
Markdown
78 lines
1.8 KiB
Markdown
---
|
|
title: web upload smoke (W5)
|
|
description: Offline validate + save into file: storage.
|
|
import web:ext/web/web.mq.md
|
|
import plugin:lib/plugin.mq.md
|
|
import sys:lib/sys.mq.md
|
|
---
|
|
|
|
# main
|
|
|
|
**p = > plugin.native_path name="web"**
|
|
1. `p`
|
|
> plugin.load path=`p`
|
|
2. *
|
|
> sys.exit code=1
|
|
|
|
`types` =
|
|
|
|
| 类型 | 扩展名 |
|
|
|------|--------|
|
|
| image/png | png |
|
|
| text/plain | txt |
|
|
|
|
**m = > web.media**
|
|
**ok = > `m`.validate filename="a.png" content_type="image/png" size=100 max_bytes=1000 types=`types`**
|
|
**ook = [ok](ok)**
|
|
1. `ook`
|
|
> print text=validate-ok
|
|
2. *
|
|
> print text=validate-fail
|
|
|
|
**bad = > `m`.validate filename="a.exe" content_type="application/octet-stream" size=100 max_bytes=1000 types=`types`**
|
|
**bok = [ok](bad)**
|
|
1. `bok`
|
|
> print text=reject-type-fail
|
|
2. *
|
|
> print text=reject-type-ok
|
|
|
|
**big = > `m`.validate filename="a.png" content_type="image/png" size=9000 max_bytes=1000 types=`types`**
|
|
**gok = [ok](big)**
|
|
1. `gok`
|
|
> print text=reject-size-fail
|
|
2. *
|
|
> print text=reject-size-ok
|
|
|
|
**blob = > web.storage url="file:tests/ext/web-fixtures/data/upload-blobs"**
|
|
**m = > web.media storage=`blob`**
|
|
**saved = > `m`.save path="tests/ext/web-fixtures/upload/sample.txt" content_type="text/plain" prefix="smoke/"**
|
|
**sok = [ok](saved)**
|
|
**skey = [key](saved)**
|
|
1. `sok`
|
|
> print text=save-ok
|
|
2. *
|
|
> print text=save-fail
|
|
|
|
**got = > `blob`.get key=`skey`**
|
|
**body = [body](got)**
|
|
1. `body` == "hello-upload"
|
|
> print text=save-roundtrip-ok
|
|
2. *
|
|
> print text=save-roundtrip-fail
|
|
|
|
<!-- form file field renders with multipart enctype -->
|
|
|
|
`fields` =
|
|
|
|
| name | label | type |
|
|
|------|-------|------|
|
|
| title | Title | text |
|
|
| file | File | file |
|
|
|
|
**frm = > web.form table="x" fields=`fields`**
|
|
**html = > `frm`.render id="up"**
|
|
1. `html`
|
|
> print text=form-file-ok
|
|
2. *
|
|
> print text=form-file-fail
|