If I were to have the time to take a stab at this I'd do it the way Fil suggested which is to add the top level onprogress event handler.
Simon Mac Donald http://hi.im/simonmacdonald On Tue, Jul 10, 2012 at 12:26 PM, Filip Maj <[email protected]> wrote: > Thanks for taking a stab at this! I guess I shouldn't be surprised someone > attempts to fix this judging by the amount of interest on IRC / the JIRA > thread in this feature :) > > Here is my feedback: > > 1. I would add this feature as a top-level FileTransfer event callback. > So, no matter if you fire off upload() or download(), you would get a > progress event. In the spirit of other APIs like the File API, I would > implement it so that users could do something like: > > var ft = new FileTransfer(); > ft.onprogress = function(evt) { > if (evt.type == 'upload') { > } else { > } > }; > > We could also reuse a lot of existing javascript in the cordova-js project > [1], as we have an implementation of W3C's ProgressEvent [2]. That said, > this would require a little bit of additional work. Each FileTransfer > instance would need an ID (tie it into the callback ID?), to handle the > case where multiple FileTransfer objects are instantiated and running at > the same time. So, a bunch of effort would still need to go into the > cordova-js project. > > 2. The Java code referenced in your implementation [3] would need a bit of > rework with the above in mind. > 3. Last but certainly not least: platform parity. > > With all of the above, I think it would be safe to try to slate this for > after 2.0. > > My 2 cents. > > [1] > https://github.com/apache/incubator-cordova-js/blob/master/lib/common/plugi > n/ProgressEvent.js > [2] http://www.w3.org/TR/progress-events/ > [3] > https://github.com/brion/incubator-cordova-android/commit/c8c1769a65535e2ef > 1ccf915248ab97ef473ef22 > > On 7/3/12 3:45 PM, "Brion Vibber" <[email protected]> wrote: > >>Consensus seems to be that FileTransfer should get deprecated in favor of >>an XHR2 polyfill, but until that's done there seem to be lots of folks who >>would love to get progress callbacks from FileTransfer (those of us doing >>binary files I think can't rely on current XHR support). >> >>I've whipped up a quick patch for FileTransfer.upload() on Android that >>calls the success callback with progress updates if you opt-in for it with >>a parameter: >>https://issues.apache.org/jira/browse/CB-622?focusedCommentId=13406124#com >>ment-13406124 >> >>The current patch is a little sub-ideal in that it uses the options.params >>array and doesn't strip the 'progress' item out; with more polish that >>could be sent as a separate argument. Possibly the JS could be tweaked so >>you can just set a function callback as options.progress? >> >>Please let me know if this sounds sane before I go finishing it up and >>adding support for download and iOS. :) >> >>-- brion vibber (brion @ pobox.com / bvibber @ wikimedia.org) >
