[OSX Core Foundation]如何通过 HTTP 异步上传文件并在发送流字节时调用回调?
在 MacOSX 上,使用 Core Foundation,我想通过 REST API 将大文件(数百兆字节)上传到远程服务器。 由于文件很大,而且我还需要给用户一些反馈,所以我想实现一个简历上传功能,并向用户反馈写入的字节数。
我首先遵循 Apple Guide 进行 CFNetwork 编程: http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/CFFTPTasks/CFFTPTasks.html#//apple_ref/doc/uid /TP30001132-CH9-SW1 但文件的异步上传仅适用于FTP。
我尝试使用 CFReadStreamCreateForHTTPRequest 但我只收到响应回调。 我尝试使用 CFReadStreamCreateForHTTPStreamedRequest 并在 ReadStreamRef 主体参数上设置了委托,但即使我在实际在运行循环上调度流之前打开流,它也永远不会被调用。
如果有人有一些关于如何做到这一点的提示,那就太好了。 多谢!
-- 雷米
on MacOSX, with Core Foundation, I want to upload a large file (several hundreds of megabytes) to a remote server through a REST API.
Since the file is big and I also need to give the user some feedback, I want to implement a resume upload feature and gives the user feedback on the number of bytes written.
I first followed the Apple Guide for CFNetwork programming: http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/CFFTPTasks/CFFTPTasks.html#//apple_ref/doc/uid/TP30001132-CH9-SW1
But the asynchronous upload of file is for FTP only.
I tried to use CFReadStreamCreateForHTTPRequest butI only got callbacks on response.
I tried with CFReadStreamCreateForHTTPStreamedRequest and I set a delegate on the ReadStreamRef body parameter but it is never called even though I open the stream before actually scheduling it on the runloop.
If somebody has some tips about how to do it, it would be great.
Thanks a lot!
--
Rémy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里得到了答案: http://lists.apple.com/archives /macnetworkprog/2010/Dec/msg00000.html。
对于上传反馈,我在创建请求时使用在运行循环上安排的计时器:
对于恢复,有两个步骤。
在正确的偏移处寻找本地内容流
创建本地内容流(但尚未打开)后,我可以使用
配置http标头
在其中进行查找,我没有webdav 风格的远程服务器,因此我使用 HTTP Range 标头来通知服务器我要上传文件的哪一部分。此步骤取决于远程服务器的期望。
希望这会有所帮助。
I got an answer here: http://lists.apple.com/archives/macnetworkprog/2010/Dec/msg00000.html.
For upload feedback, I use a timer scheduled on the runloop when creating the request:
For resume, there are two steps.
Seek the local content stream at the good offset
Once the local content stream created (but not yet opened), I can seek in it using
Configure http headers
I don't have webdav style remote server, so I use HTTP Range headers to inform the server about which part of the file I want to upload. This step depends on what the remote server expects.
Hope this will help.