Can a web service return a stream?

前端 未结 12 1722
眼角桃花
眼角桃花 2021-02-02 09:23

I\'ve been writing a little application that will let people upload & download files to me. I\'ve added a web service to this applciation to provide the upload/download fun

12条回答
  •  北海茫月
    2021-02-02 09:45

    Stephen Denne has a Metro implementation that satisfies your requirement. My answer is provided below after a short explination as to why that is the case.

    Most Web Service implementations that are built using HTTP as the message protocol are REST compliant, in that they only allow simple send-receive patterns and nothing more. This greatly improves interoperability, as all the various platforms can understand this simple architecture (for instance a Java web service talking to a .NET web service).

    If you want to maintain this you could provide chunking.

    boolean uploadFile(String username, String password, String fileName, int currentChunk, int totalChunks, byte[] chunk);
    

    This would require some footwork in cases where you don't get the chunks in the right order (Or you can just require the chunks come in the right order), but it would probably be pretty easy to implement.

提交回复
热议问题