Android DownloadManager with gRPC

2020-03-26 android c++ rest grpc

Currently working on an API which make the client (Android/Kotlin) being able to download a video from the server. With a traditional HTTP URI it would be a pretty easy task, I would just DownloadManager and the problem is solved. However, I'm using gRPC (c++) for the server.

I currently have a solution with Kotlin flows which basically take the unidirectional stream from the server and consume the file chunk to store them in local file. However, even if it works for the major parts, It has a lot of corner cases and that is why I want to use DownloadManager. For further information on what I have currently please check: Handling file download with gRPC on Android

After looking for a solution for a little while now, I found that it is possible to map the RPC call to REST API by using this project and basically do something like:

rpc Download(DownloadRequest) returns (DownloadResponse) {
   option (google.api.http) = {
      post: "/v1/download"
      body: "*"
   };
}

or use a YAML file to configure the google API.

All of this seems to be pretty convenient while using Google Cloud and Golang but I'm creating a standalone server in C++.

So there are two questions here:

  • Is it possible to serve static file in a REST way with gRPC c++

  • Is there another way to use DownloadManager with gRPC ?

Answers

As the commenter on the question suggested, gRPC is for structured data not raw file downloads. Trying to map between a URI and the RPC call would not be enough to make DownloadManager work with gRPC, because the gRPC server is going to send and expect additional data beyond the raw file itself that will not be understood or sent by DownloadManager.

You can certainly use gRPC server and client to send large files, but it's not going to have the same set of features built-in for large file downloading (such as resuming your download later if the connection is broken) as using something like a HTTP server + a specific file download library/client. I would recommend just running a separate HTTP server for your file download needs.

[crossposting my answer from the grpcio mailing list]

Related