File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 9
9
"net/http"
10
10
"os"
11
11
"path/filepath"
12
+ "html/template"
12
13
)
13
14
14
15
const maxUploadSize = 2 * 1024 * 1024 // 2 mb
@@ -26,6 +27,11 @@ func main() {
26
27
27
28
func uploadFileHandler () http.HandlerFunc {
28
29
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
30
+ if r .Method == "GET" {
31
+ t , _ := template .ParseFiles ("upload.gtpl" )
32
+ t .Execute (w , nil )
33
+ return
34
+ }
29
35
if err := r .ParseMultipartForm (maxUploadSize ); err != nil {
30
36
fmt .Printf ("Could not parse multipart form: %v\n " , err )
31
37
renderError (w , "CANT_PARSE_FORM" , http .StatusInternalServerError )
Original file line number Diff line number Diff line change
1
+ < html>
2
+ < head>
3
+ < title> Upload file< / title>
4
+ < / head>
5
+ < body>
6
+ < form enctype= " multipart/form-data" action= " http://localhost:8080/upload" method= " post" >
7
+ < input type= " file" name= " uploadFile" / >
8
+ < input type= " submit" value= " upload" / >
9
+ < / form>
10
+ < / body>
11
+ < / html>
You can’t perform that action at this time.
0 commit comments