I'm trying to upload images from my computer to a website using go. Usually, I use a bash script that sends a file and a key to the server:
curl -F "image"=@"IMAGEFILE" -F "key"="KEY" URL
it works fine, but I'm trying to convert this request into my golang program.
http://matt.aimonetti.net/posts/2013/07/01/golang-multipart-file-upload-example/
I tried this link and many others, but, for each code that I try, the response from the server is "no image sent", and I've no idea why. If someone knows what's happening with the example above.
Thanks
I have found this tutorial very helpful to clarify my confusions about file uploading in Go.
Basically you upload the file via ajax using
form-data
on a client and use the following small snippet of Go code on the server:Here
r
is*http.Request
. P.S. this just stores the file in the same folder and does not perform any security checks.Here's some sample code.
In short, you'll need to use the
mime/multipart
package to build the form.Regarding attila-o's post, the request header doesn't have the boundary since the Writer is closed already.
So, it should close after the set, I think.