Conventional, browser-based uploads use POST requests, where the request
body contains the content of all form fields (including files) in MIME
multipart encoding.
IIRC, curl can use this upload method as well. With --upload-file
however, it sends a PUT request with the contents of the single file
specified on the command line as body. In the simplest case, something
like "io.Copy(file, req.Body)" should do what you want.
On 08.10.2014 10:14, Budh Ram wrote:
> Thanks Tobias for reply.
>
> But instead of uploading file from form request, I want to upload it
> using curl --upload-file syntax as:
>
> curl --upload-file foo.txt
http://localhost:9090/rp.txt
>
>
> When I use "file, header, err := r.FormFile("file")", I get error as:
>
> request Content-Type isn't multipart/form-data
>
>
> on above mentioned curl command.
>
> On Tuesday, 7 October 2014 19:26:09 UTC+5:30, Budh Ram wrote:
>
> Hi Guys,
>
> I am newbie in Go language.
> I am writing a small HttpServer in Go where I want to upload file to
> this server using curl approach as:
>
> curl --upload-file foo.txt
http://localhost:9090/rp.txt
>
>
> I am getting following server logs:
>
https://gist.github.com/budhrg/355126ba4f03d32008e0
> <
https://gist.github.com/budhrg/355126ba4f03d32008e0>
>
> I searched through docs, existing codes but the closest I found is
> file upload using web
> <
https://github.com/Blacktremolo/goload/blob/master/main.go#L49>.
>
> Following is my code for HttpServe which I need to update to accept
> file content and save in server:
>
> package main
>
>
> import (
>
> "fmt"
>
> "net/http"
>
> )
>
>
> func main() {
>
> http.Handle("/", http.HandlerFunc(upload))
>
> http.ListenAndServe("localhost:9090", nil)
>
> }
>
>
> func upload(w http.ResponseWriter, req *http.Request) {
>
> fmt.Fprintf(w, "file name is : %s",req.URL.Path[1:])
>
> fmt.Println("method :", req.Method)
>
> fmt.Println("FileSize : ", req.ContentLength)
>
> fmt.Println("Header : ",req.Header)
>
> fmt.Println("Body : ",req.Body)
>
> fmt.Println("Post form : ",req.PostForm)
>
> }
>
>
>
> Please help
>
> --
> 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...@googlegroups.com
> <mailto:
golang-nuts...@googlegroups.com>.
> For more options, visit
https://groups.google.com/d/optout.