开发者

progress while uploading file from iPhone

I'm uploading a file from an iPhone to a server with an HTTP POST, and monitoring the progress in NSURLConnection's connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite. The problem is that the progress is not smooth. The beginning of the file goes by very fast in four 32K chunks, then the progress ticks by more slowly with smaller chunks until the total is reached. Then didSendBodyData doesn't get called anymore for some time before the response finally comes back开发者_如何学JAVA. The progress bar being driven by the code therefore goes fast (almost instantaneously) for the first 128K, then slow, then "sticks" at 100% for a long time.

Some research implies that the first four chunks are instantly going into the phone's "kernel buffer," and from then on data trickles into the buffer as data trickles out the other end. Progress reaches 100% when the last of the data trickles in, but then sticks while the buffer empties on the back side.

I'd much prefer to show progress based on the data coming out the back end, or not have a buffer at all. Anyone know how I can do this?


Have you looked into ASIHTTPRequest for progress monitoring? If I remember correctly (and I might not) the code allows you to customize the update progress "chunk" intervals.


From the ASIHTTPRequest homepage:

Tracking progress for uploads where the request body is less than 128KB is currently not possible. For requests larger than 128KB, progress delegates will not receive information on the progress of the first 128KB of post data. This is because of limitations in the CFNetwork API.

then he adds:

Update 21st June 2009: The wonderful folks at Apple were kind enough to address my bug report! In the iPhone 3.0 SDK, it looks like the buffer size has been reduced to 32KB, which makes accurate upload progress tracking a lot more reliable.

I've installed the demo app onto my iPhone and tried uploading a ~140kb file and the progress still doesn't seem to be accurate. From my findings, yes the buffer size has been reduced to 32kb but the callback method only gets called once 4 of these buffers have been filed up (so it has hit 128kb). Progress indicators remain to seem useless for small files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜