forked from go-xweb/xweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.go
54 lines (45 loc) · 1.03 KB
/
upload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"github.com/go-xweb/xweb"
)
var page = `
<html>
<head><title>Multipart Test</title></head>
<body>
<form action="/" enctype="multipart/form-data" method="POST">
<label for="file"> Please select a File </label>
<input id="file" type="file" name="file"/>
<br>
<label for="input1"> Please write some text </label>
<input id="input1" type="text" name="input1"/>
<br>
<label for="input2"> Please write some more text </label>
<input id="input2" type="text" name="input2"/>
<br>
<input type="submit" name="Submit" value="Submit"/>
</form>
</body>
</html>
`
type MainAction struct {
*xweb.Action
upload xweb.Mapper `xweb:"/"`
Id int
Input1 string
Input2 string
}
func (c *MainAction) Upload() {
if c.Method() == "GET" {
c.Write(page)
} else if c.Method() == "POST" {
savefile := "./a"
c.SaveToFile("file", savefile)
c.Write("<p>input1: %v </p>", c.Input1)
c.Write("<p>input2: %v </p>", c.Input2)
c.Write("<p>file: %v</p>", savefile)
}
}
func main() {
xweb.AddAction(&MainAction{})
xweb.Run("0.0.0.0:9999")
}