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>
1.8 KiB
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"
p
plugin.load path=
p
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
ook
print text=validate-ok
print text=validate-fail
bad = > m.validate filename="a.exe" content_type="application/octet-stream" size=100 max_bytes=1000 types=types
bok = ok
bok
print text=reject-type-fail
print text=reject-type-ok
big = > m.validate filename="a.png" content_type="image/png" size=9000 max_bytes=1000 types=types
gok = ok
gok
print text=reject-size-fail
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
skey = key
sok
print text=save-ok
print text=save-fail
got = > blob.get key=skey
body = body
body== "hello-upload"
print text=save-roundtrip-ok
print text=save-roundtrip-fail
fields =
| name | label | type |
|---|---|---|
| title | Title | text |
| file | File | file |
frm = > web.form table="x" fields=fields
html = > frm.render id="up"
html
print text=form-file-ok
print text=form-file-fail