examples: improve examples/vweb/file_upload
parent
3c6356ba36
commit
637ebe5d42
|
@ -12,6 +12,7 @@ File form:
|
||||||
<form method="POST" enctype="multipart/form-data" action="/upload">
|
<form method="POST" enctype="multipart/form-data" action="/upload">
|
||||||
<input type="hidden" name="file_id" value="aafueB5Quie" />
|
<input type="hidden" name="file_id" value="aafueB5Quie" />
|
||||||
<input type="file" name="upfile" multiple/>
|
<input type="file" name="upfile" multiple/>
|
||||||
|
<input type="hidden" name="another_hidden_field" value="abcxyz" />
|
||||||
<input type="submit" value="Upload"/>
|
<input type="submit" value="Upload"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<meta charset="utf-8">
|
||||||
|
|
||||||
|
Submitted form info:
|
||||||
|
|
||||||
|
@for name, value in form_data
|
||||||
|
|
||||||
|
<h2>name: @name</h2>
|
||||||
|
<p>value: @value</p>
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
<a href="/">Back</a>
|
|
@ -2,9 +2,7 @@ module main
|
||||||
|
|
||||||
import vweb
|
import vweb
|
||||||
|
|
||||||
const (
|
const port = 8082
|
||||||
port = 8082
|
|
||||||
)
|
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
vweb.Context
|
vweb.Context
|
||||||
|
@ -20,13 +18,20 @@ pub fn (mut app App) index() vweb.Result {
|
||||||
|
|
||||||
['/upload'; post]
|
['/upload'; post]
|
||||||
pub fn (mut app App) upload() vweb.Result {
|
pub fn (mut app App) upload() vweb.Result {
|
||||||
|
dump(app.form)
|
||||||
|
dump(app.files)
|
||||||
fdata := app.files['upfile']
|
fdata := app.files['upfile']
|
||||||
|
|
||||||
mut files := []vweb.RawHtml{}
|
mut files := []vweb.RawHtml{}
|
||||||
|
|
||||||
for d in fdata {
|
for d in fdata {
|
||||||
files << d.data.replace_each(['\n', '<br>', '\n\r', '<br>', '\t', ' ', ' ', ' '])
|
files << d.data.replace_each(['\n', '<br>', '\n\r', '<br>', '\t', ' ', ' ', ' '])
|
||||||
}
|
}
|
||||||
|
|
||||||
return $vweb.html()
|
return $vweb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
['/submit'; post]
|
||||||
|
pub fn (mut app App) submit() vweb.Result {
|
||||||
|
dump(app.form)
|
||||||
|
form_data := app.form.clone()
|
||||||
|
return $vweb.html()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue