FAQ
Ahh Wang,

Thanks. It worked.

Thanks a lot.
On Monday, 22 July 2013 18:22:35 UTC+5:30, Srinath G S wrote:


Hi all,
Two issues
1) I am trying to upload files to the server using net/http package.

The upload functionality works fine. It even saves the file to disk.

But when the form is submitted without any files in it, it gets trapped in
the if condition for the fileErr. Code below

uploadedFile,upF,fileErr := r.FormFile("img")
defer uploadedFile.Close()
if fileErr != nil{
Vi.error = true
fmt.Println("inside fileerr")
renderTemplate(w,"fooView",Vi)
//http.Error(w,fileErr.Error(),http.StatusInternalServerError)
fmt.Println("after render")
return
}


But it also raises the following error.

2013/07/22 18:06:35 http: panic serving 127.0.0.1:57321: runtime error:
invalid memory address or nil pointer dereference
goroutine 8 [running]:
net/http.func·007()
/usr/local/go/src/pkg/net/http/server.go:1022 +0xac
main.postHandler(0xc2000affc0, 0xc20011ab60, 0xc200124270)
/home/dastan/101010/ps-go/try.go:47 +0x25d
net/http.HandlerFunc.ServeHTTP(0x72c218, 0xc2000affc0, 0xc20011ab60,
0xc200124270)
/usr/local/go/src/pkg/net/http/server.go:1149 +0x3e
github.com/gorilla/mux.(*Router).ServeHTTP(0xc2000b3410, 0xc2000affc0,
0xc20011ab60, 0xc200124270)
/home/dastan/go/src/github.com/gorilla/mux/mux.go:86 +0x1d9
net/http.(*ServeMux).ServeHTTP(0xc2000c2510, 0xc2000affc0, 0xc20011ab60,
0xc200124270)
/usr/local/go/src/pkg/net/http/server.go:1416 +0x11d
net/http.serverHandler.ServeHTTP(0xc2000b3500, 0xc2000affc0, 0xc20011ab60,
0xc200124270)
/usr/local/go/src/pkg/net/http/server.go:1517 +0x16c
net/http.(*conn).serve(0xc2000e1510)
/usr/local/go/src/pkg/net/http/server.go:1096 +0x765
created by net/http.(*Server).Serve
/usr/local/go/src/pkg/net/http/server.go:1564 +0x266


files in the archive,

Archive: try.zip
Length Date Time Name
--------- ---------- ----- ----
1517 2013-07-22 18:06 try.go
6499744 2013-07-22 18:06 try
1987 2013-07-22 18:05 views/fooView.html
--------- -------
6503248 3 files


Here is what I' trying to do.

If no file is uploaded to server, I would want to render the same template
with the markup for error displayed.

2) None of the HTML part after the if statement appears in the rendered
html.

The binary in the archive is built for 64 bit machine.
http://localhost:8081/something/ for accessing the html page.

As the template did not render the submit button, I used Javascript to
submit the form for testing.

Help will be greatly appreciated.

Thanks and Regards,
Srinath
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 22, '13 at 12:52p
activeJul 22, '13 at 2:39p
posts5
users2
websitegolang.org

2 users in discussion

Srinath G S: 4 posts Steve wang: 1 post

People

Translate

site design / logo © 2021 Grokbase