```message File { bytes file_bytes = 1; } messa...
# grpc
s
Copy code
message File {
   bytes file_bytes = 1;
}
message Response {
   string some_response = 1;
}
Service UploadService {
   rpc uploadFiles(stream File) returns Response;
}
How can I define a service that takes List of Files as a parameter ? The above is fine for a single file.
s
you need to create a new message that will contain a list of files. I do not know your case, but the stream seems redundant, if you want to pass a list of files as parameter. You can however achieve the same functionality with the stream, by passing one file at a time
s
grpc has no support for Files right ? We need to pass them as a stream of bytes as far as I can see , please correct me if I am wrong
s
I'm not sure myself. It seems reasonable not to have file support. Well, if it is a stream of bytes, or an array of bytes is up to you and your needs
s
I guess my question is if we can support a list of files if we go stream of bytes route
s
yes, you can
you will send a stream of File, meaning that you will emit one File at a time, using a stream. when it is consumed, the server will create the response
s
File might be a misleading name , i guess i can name it FileBytes , I can stream and collect them on the server side , my question is how to do this for a list of files , maybe add a flag or a file index in the FileBytes definition but i am not sure if that's the recommended way
Copy code
message FileBytes {
   int32_t file_index = 1;
    bytes byte_stream = 2;
}
something like this
s
a single
byte_stream
should contain a whole file. if the file is too big and you want to split that to a stream as well, then you definitely need more parameters. I'm not sure how you can do that though
my initial thought is to add an optional end_of_file parameter, so that the server knows when is reading a new file, but AFAIK there are these types of characters within a file, so it may be more easy.