Stream file to client in Python GRPC Server

1,457 views
Skip to first unread message

Mark

unread,
Sep 6, 2018, 2:03:57 AM9/6/18
to grpc.io
I have asked this question in SO https://stackoverflow.com/questions/52197359/sending-back-a-file-stream-from-grpc-python-server?noredirect=1#comment91343967_52197359

But I would like to try my luck here also...

I have a service that needs to return a filestream to the calling client so I have created this proto file.

    service Sample {
         rpc getSomething(Request) returns (stream Response){}
    }
    
    message Request {
    
    }
    
    message Response {
    bytes data = 1;
    }

When the server receives this, it needs to read some source.txt file and then write it back to the client
as a byte stream.  Just would like to ask is this the proper way to do this in a Python GRPC server?

    fileName = "source.txt"
    with open(file_name, 'r') as content_file:
        content = content_file.read()
    response.data = content.encode()
    yield response
I cannot find any examples related to this that is written in Python.

I am a newbie GRPC/Python Coder also, I just need to implement this functionality so please bear with me.

Nathaniel Manista

unread,
Sep 22, 2018, 10:23:06 PM9/22/18
to neli...@gmail.com, grpc.io
Reply all
Reply to author
Forward
0 new messages