Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,46 @@
|
||||
module main
|
||||
|
||||
import net.http
|
||||
import veb
|
||||
|
||||
const port = 8082
|
||||
|
||||
struct App {
|
||||
}
|
||||
|
||||
struct Context {
|
||||
veb.Context
|
||||
}
|
||||
|
||||
fn uploaded_file_contents(fdata []http.FileData) []veb.RawHtml {
|
||||
mut files := []veb.RawHtml{}
|
||||
for data in fdata {
|
||||
files << data.data.replace_each(['\n', '<br>', '\n\r', '<br>', '\t', ' ', ' ', ' '])
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut app := &App{}
|
||||
veb.run[App, Context](mut app, port)
|
||||
}
|
||||
|
||||
pub fn (mut app App) index() veb.Result {
|
||||
return $veb.html()
|
||||
}
|
||||
|
||||
@['/upload'; post]
|
||||
pub fn (mut app App) upload() veb.Result {
|
||||
dump(ctx.form)
|
||||
dump(ctx.files)
|
||||
fdata := ctx.files['upfile']
|
||||
files := uploaded_file_contents(fdata)
|
||||
return $veb.html()
|
||||
}
|
||||
|
||||
@['/submit'; post]
|
||||
pub fn (mut app App) submit() veb.Result {
|
||||
dump(ctx.form)
|
||||
form_data := ctx.form.clone()
|
||||
return $veb.html()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Test multipart/form-data file uploading</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>File Upload</h2>
|
||||
|
||||
File form:
|
||||
<form method="POST" enctype="multipart/form-data" action="/upload">
|
||||
<input type="hidden" name="file_id" value="aafueB5Quie" />
|
||||
<input type="file" name="upfile" multiple/>
|
||||
<input type="hidden" name="another_hidden_field" value="abcxyz" />
|
||||
<input type="submit" value="Upload"/>
|
||||
</form>
|
||||
|
||||
Text form:
|
||||
<form method="POST" enctype="multipart/form-data" action="/submit">
|
||||
<input type="text" name="content1" value="abc" />
|
||||
<input type="text" name="content2" value="xyz" />
|
||||
<input type="submit" value="Submit content">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,15 @@
|
||||
<meta charset="utf-8">
|
||||
|
||||
File amount: @fdata.len
|
||||
|
||||
@for i, data in fdata
|
||||
|
||||
<h2>Filename: @data.filename</h2>
|
||||
<h2>Length: @data.data.len</h2>
|
||||
<h2>Type: @data.content_type</h2>
|
||||
|
||||
<p>@{files[i]}</p>
|
||||
|
||||
@end
|
||||
|
||||
<a href="/">Back</a>
|
||||
Reference in new issue
Block a user