问题
How could I stream files(images) using Apache Thrift? I have searched a lot about Thrift and did not find any well written documentation regarding to it. Why did Facebook open sourced this project without docs?
回答1:
The way I would recommend is to set up your service to deliver data in chunks, like so:
struct DataChunk {
1 : binary data
2 : bool haveMoreData
}
service {
DataChunk GetChunk( 1 : string resource, 2: i32 offset, 3: i32 size)
}
It seems a good idea to either limit the size
to some sane value (needs to be checked on the server side), or remove the size
argument at all and always deliver chunks of a fixed, predefined size to circumvent clients asking for insanely large data blocks.
Note that the whole process needs to follow the pull model, there is no built-in push feature. However, you still can do push, you just need to run a Thrift server on the client side and pass the necessary connection info. Although this will not work in all scenarios (especially transports), it is a fully working solution where it is possible.
来源:https://stackoverflow.com/questions/26739520/how-to-stream-an-image-from-python-to-c-using-apache-thrift