File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 99 "net/http"
1010 "os"
1111 "path/filepath"
12+ "html/template"
1213)
1314
1415const maxUploadSize = 2 * 1024 * 1024 // 2 mb
@@ -26,6 +27,11 @@ func main() {
2627
2728func uploadFileHandler () http.HandlerFunc {
2829 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+ }
2935 if err := r .ParseMultipartForm (maxUploadSize ); err != nil {
3036 fmt .Printf ("Could not parse multipart form: %v\n " , err )
3137 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