Re:Go Web Examples
by jhoechtl on Friday February 10, 2017 @02:12AM
(#13613768)
I am currently searching for an example / skeleton in Go where I can upload a file via the browser to the server (drag and drop added bonus). Any examples?
[ Parent
| on HN ]
Something like this will hopefully get the point across on how to handle "multipart/form-data" forms. It will print the content of the upload to the server's stdout.
https://play.golang.org/p/DiNGdl27kE
You can use curl to test it out (it assumes a file called "foobar.txt" is available):
curl -v -F [email protected] localhost:8080/uploadI actually wrote an extremely shonky/basic file upload thing and contributed it to the weird 'illacceptanything' repository, while that was a thing, about a year and a half ago.
Maybe you'll find it helpful, maybe not. Ignore the bindata.go stuff and look at main.go (inc. file accepting) & the file upload control (w/Bootstrap fileinput.min.js) & the braindead simple HTML templating stuff.
https://github.com/leafi/illacceptanything/commit/1b78922f89...
I don't know much about Go so can't speak to the server-side handling of file uploads. The drag/drop side of things is server agnostic - I strongly recommend http://www.dropzonejs.com
This might be more of a complete app than you need, but https://transfer.sh is open source and it looks fairly compact. Could be some interesting examples in there?
Re:Go Web Examples
by bitexploder on Friday February 10, 2017 @09:29AM
(#13615551)
I really like the gophish app for easy to understand common patterns in web apps.