恢复文件上传寻求流 [英] resuming file upload seeking a stream

查看:30
本文介绍了恢复文件上传寻求流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件从客户端上传到服务器...当服务器程序接收到流时,不支持属性 Length 并且 CanSeek 为 false,怎么可能进行搜索??如果我在客户端读取它并在消息合同中作为消息头发送但不知道如何查找,我可以获得长度.想法??

I am uploading files from clients to server... when the server program receives the stream, property Length is not supported and CanSeek comes false, how would seeking be possible?? I can get the length if I read it in the client and send as a message header in the message contract but don't know how to seek. Ideas??

推荐答案

WCF 不是用于文件传输的技术.此外,内部使用的StreamFormatter 不支持seek,因为分布式应用程序中seek 的整个想法是无稽之谈.为了使这项工作正常工作,内部流必须是网络协议,对传输的数据进行控制流,这不是.在内部,流只是字节数组.这意味着即使 WCF 支持定位,您仍然需要在定位之前传输所有数据.

WCF is not technology for file transfers. Moreover seek is not supported by StreamFormatter used internally because the whole idea of seek in distributed application is nonsense. To make this work correctly internal stream will have to be network protocol with control flow over transferred data which is not. Internally the stream is only array of bytes. It means that even if WCF supported seeking you would still need to transfer all data before seek position.

如果您需要恢复功能,您必须自己通过手动创建数据块并上传它们并将它们附加到服务器上的文件来实现它.服务器将控制最后正确接收的块并拒绝已经通过的块.MSDN 有示例实现将此用作自定义频道.

If you need resume functionality you must implement it by yourselves by manually creating chunks of data and uploading them and appending them to file on the server. Server will control last correctly received chunk and refuse chunks already passed. MSDN has sample implementation using this as custom channel.

这篇关于恢复文件上传寻求流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆