We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can i upload file use go json rest? I am just use this code to do success!
func upload(w rest.ResponseWriter, r *rest.Request) { r.ParseMultipartForm(32 << 20) file, handler, err := r.FormFile("uploadfile") if err != nil { fmt.Println(err) return } defer file.Close() f, err := os.OpenFile(handler.Filename, os.O_WRONLY|os.O_CREATE, 0666) if err != nil { fmt.Println(err) return } defer f.Close() io.Copy(f, file) fmt.Fprintln(w.(http.ResponseWriter), "upload ok!") }
func index(w rest.ResponseWriter, r *rest.Request) { w.(http.ResponseWriter).Header().Set("Content-Type","text/html") w.(http.ResponseWriter).Write([]byte(tpl)) }
const tpl = `
The text was updated successfully, but these errors were encountered:
No branches or pull requests
how can i upload file use go json rest? I am just use this code to do success!
func upload(w rest.ResponseWriter, r *rest.Request) {
r.ParseMultipartForm(32 << 20)
file, handler, err := r.FormFile("uploadfile")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
f, err := os.OpenFile(handler.Filename, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
fmt.Fprintln(w.(http.ResponseWriter), "upload ok!")
}
func index(w rest.ResponseWriter, r *rest.Request) {
w.(http.ResponseWriter).Header().Set("Content-Type","text/html")
w.(http.ResponseWriter).Write([]byte(tpl))
}
const tpl = `
<title>上传文件</title> `The text was updated successfully, but these errors were encountered: