How to implement a file download service in GRPC

2,964 views
Skip to first unread message

Rampradeep Nalluri

unread,
Jul 30, 2019, 7:49:54 PM7/30/19
to golang-nuts
It is easy to pipe a file reader to http.ResponseWriter object using io.copy() when I implement a large file download service over REST. But how do we handle similar requirement with gRPC server to REST client?

what is the standard way?

-Ram

Burak Serdar

unread,
Jul 30, 2019, 8:42:15 PM7/30/19
to Rampradeep Nalluri, golang-nuts
I don't know what the standard way is, but I do something similar
using a grpc stream. You have to deal with breaking the data into
chunks and stream to the grpc server.

You could implement a client-side streaming API to receive the file
via grpc on the receiving side, implement a Write([]byte) method on
the sending side with chunking etc. and use copy().

>
> -Ram
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/903ac408-ff6c-4c0b-a4f7-801d4d6f7110%40googlegroups.com.

Rampradeep Nalluri

unread,
Jul 31, 2019, 10:26:08 AM7/31/19
to Burak Serdar, golang-nuts
If we do that clients like browsers or curl can not use the download API directly.

Burak Serdar

unread,
Jul 31, 2019, 10:35:54 AM7/31/19
to Rampradeep Nalluri, golang-nuts
On Wed, Jul 31, 2019 at 8:25 AM Rampradeep Nalluri
<n.ramp...@gmail.com> wrote:
>
> If we do that clients like browsers or curl can not use the download API directly.

True. You would need an API front-end to expose the grpc stream.

Edward Muller

unread,
Jul 31, 2019, 4:27:32 PM7/31/19
to Rampradeep Nalluri, golang-nuts

Rampradeep Nalluri

unread,
Aug 1, 2019, 4:12:35 PM8/1/19
to Edward Muller, golang-nuts
Reply all
Reply to author
Forward
0 new messages