可以通过 HTTP 进行文件管道吗?
当其他应用程序正在服务器上写入该文件时,是否可以通过 http 管道或流式传输文件?
Is it possible to pipe or stream a file over http while other application is writing to that file on the server ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的。
如果其他应用程序尚未获得文件的独占锁定,您可以继续阅读,直到找到一个 eof。如果没有 eof,则文件仍在写入中。
然后,您可以使用分块编码通过http发送文件。这样您就不必在发送之前缓冲整个文件。
你有特定的语言吗?
Yes, this is possible.
If the other application has not obtained an exclusive lock on the file, you can keep reading until you find an eof. if there is no eof, the file is still being written too.
You then would send the file over http using chunked encoding. This way you don't have to buffer the whole file before sending it.
Do you have a particular language?
流式传输可以通过 MIME 类型 multipart/x-mixed-replace 在纯 HTTP 中实现。如果您想在浏览器中执行此类操作,请注意它在 IE 中不起作用(像往常一样),因此您应该退回到 AJAX 和轮询行为。
Streaming can be achieved in pure HTTP via MIME type multipart/x-mixed-replace. If you're looking to do this kind of thing in a browser, be aware that it doesn't work in IE (as usual), so then you should fall back to AJAX and polling behavior.
HTTP 是一种请求-响应协议。如果客户端向服务器发送请求,服务器会反序列化该请求,执行一些工作,然后发送响应。如果服务器选择,它可以将其喜欢的任何内容流式传输回调用者,并且仅在完成后关闭连接。
但是,客户端必须意识到它将在响应中接收数据流,并且必须能够并且愿意处理传入的提要。
我们将此功能内置到 Windows Communication Foundation (WCF) 中,使服务能够通过 HTTP、TCP 和命名管道将大型 Blob 流式传输回客户端。
HTTP is a request-response protocol. If a client sends a request to a server, the server deserializes the request, does some work and then sends a response. If the server chooses, it can stream any content it likes back to the caller and only close the connection once it's done.
However, the client must be aware of the fact that it'll be receiving a stream of data in the response and must be able and willing to process the incoming feed.
We built this capability into Windows Communication Foundation (WCF) to enable services to stream large blobs back to clients via HTTP as well as TCP and Named Pipes.