Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add meteor http events #3266

Closed
smeijer opened this issue Dec 9, 2014 · 2 comments
Closed

add meteor http events #3266

smeijer opened this issue Dec 9, 2014 · 2 comments

Comments

@smeijer
Copy link

smeijer commented Dec 9, 2014

Should be great if we could bind to events from the xhr stream. Like for example 'onprogress' for monitoring progress of a file upload. This is currently the only thing preventing me from using Meteor.http instead of other xhr libraries.


Example usage:

var _reactiveDict = new ReactiveDict({
  progress: 0 
});

var result = HTTP.call('put', 'http://external-service...', {
  headers: {
     'X-Auth-Token': 'myToken'
  },
  events: {
    'progress': function(p) { 
      _reactiveDict.set('progress', p); 
    }
  },
  content: uploadedFile
});

Tracker.autorun(function() {
   var uploadProgress = _reactiveDict.get('progress');
   console.log('uploading file: ' + uploadProgress + '%');
});
@glasser
Copy link
Contributor

glasser commented Jan 12, 2015

Thanks for the feature request! You might be interested in reading our feature request guidelines.

@robertpitt
Copy link
Contributor

This could be solved by t he referenced PR above.

var result = HTTP.call('put', 'http://external-service...', {
  headers: {
     'X-Auth-Token': 'myToken'
  },

  beforeSend: function(xhr){
    xhr.onprogress = function(){
      if (e.lengthComputable) {
         _reactiveDict.set('progress', (e.loaded / e.total) * 100); 
      }
    }
  },
  content: uploadedFile
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants