rest apis in golang accepting a file upload and another API to stream the file content

1,856 views
Skip to first unread message

suman....@gmail.com

unread,
Nov 26, 2015, 9:15:16 PM11/26/15
to golang-nuts
Is there any example of uploading a file to Rest API (POST) implemented using Gorilla library in Go? This API should be accessible via curl, chrome Rest client or any other http rest clients.
Examples I googled show uploading from a web page Form.

Giulio Iotti

unread,
Nov 27, 2015, 10:48:36 AM11/27/15
to golang-nuts, suman....@gmail.com
On Friday, November 27, 2015 at 4:15:16 AM UTC+2, suman....@gmail.com wrote:
Is there any example of uploading a file to Rest API (POST) implemented using Gorilla library in Go? This API should be accessible via curl, chrome Rest client or any other http rest clients.
Examples I googled show uploading from a web page Form.

You don't really need Gorilla to do this, unless you have complicated routes (URL paths for actions); in that case use Gorilla mux.

For uploading a file, there are plenty of examples, for example this[1].

To "stream" a file, just open it and use the resulting Reader in io.Copy() on the http.ResponseWriter: io.Copy(respWriter, fileReader).

suman....@gmail.com

unread,
Nov 28, 2015, 6:40:05 PM11/28/15
to golang-nuts, suman....@gmail.com
Thanks for the response. But io,Copy is failing while dealing with large files (570MB).

http://stackoverflow.com/questions/33976409/stream-file-from-gridfs-in-rest-api-using-go is the approach I am following. How can I fix it to work with large files?

Staven

unread,
Nov 28, 2015, 6:57:29 PM11/28/15
to golang-nuts
On Sat, Nov 28, 2015 at 02:38:22PM -0800, suman....@gmail.com wrote:
> Thanks for the response. But io,Copy is failing while dealing with large
> files (570MB).

Failing how?

> http://stackoverflow.com/questions/33976409/stream-file-from-gridfs-in-rest-api-using-go
> is the approach I am following. How can I fix it to work with large files?

File Not Found

kalpan...@gmail.com

unread,
Nov 29, 2015, 11:31:01 AM11/29/15
to golang-nuts, suman....@gmail.com
My bad. It works perfect with io,Copy. Thanks.




On Thursday, November 26, 2015 at 8:15:16 PM UTC-6, suman....@gmail.com wrote:

rugwir...@gmail.com

unread,
Apr 19, 2018, 12:06:21 PM4/19/18
to golang-nuts
Actually I have almost the same scenario: I am trying to upload large files as a stream. Do you think the io.Copy() method would work for me? If not what do you recommend.
Reply all
Reply to author
Forward
0 new messages