vweb: add multipart/form-data parser and file upload (#8160)

This commit is contained in:
Louis Schmieder 2021-01-21 11:08:51 +01:00 committed by GitHub
parent b44ec4921f
commit f7c251f8f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 2 deletions

View file

@ -0,0 +1,33 @@
module main
import vweb
const (
port = 8082
)
struct App {
vweb.Context
}
fn main() {
vweb.run<App>(port)
}
pub fn (mut app App) index() vweb.Result {
return $vweb.html()
}
[post]
['/upload']
pub fn (mut app App) upload() vweb.Result {
fdata := app.files['upfile']
mut files := []vweb.RawHtml{}
for d in fdata {
files << d.data.replace_each(['\n', '<br>', '\n\r', '<br>' '\t', ' ', ' ', '&nbsp;'])
}
return $vweb.html()
}