gRPC Java文件下载示例 [英] gRPC Java File Download Example

查看:624
本文介绍了gRPC Java文件下载示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用gRPC来实现文件下载功能的方法,但是我无法在文档中找到实现方法.

I am looking for a way on how to implement file download functionality using gRPC but I can't find in the documentation how this is done.

执行此操作的最佳方法是什么?我想要一个拥有文件的gRPC服务器和一个从gRPC请求某些内容的gRPC客户端.

What is an optimal way to do this? I wanted to have a gRPC server that holds files and a gRPC client to request something from gRPC.

我看过Java中的示例,但找不到解决方法.我今天才开始阅读有关gRPC的信息.

I have looked at the examples in Java but could not figure out a way on how to do this. I just started reading about gRPC today.

推荐答案

必须将特定的message定义为数据容器,并且必须使用stream将其分块传输到客户端.

You must define a specific message as data container and you must transfer it to the client in chunks using a stream.

原始消息和RPC服务示例:

Example of proto Message and RPC service:

message DataChunk {
   bytes data = 1;
}

rpc DownloadProductImage(DownloadProductImageRequest) returns(stream DataChunk){}

在Java中,您可以使用BufferedInputStream将资源流式传输到客户端.

In java you can use BufferedInputStream to stream the resource to the client.

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆