Skip to content

Feature - add support for asynchronous filters - #289

Closed
davemaurakis wants to merge 1 commit into
nervgh:masterfrom
davemaurakis:feature/async-filters
Closed

davemaurakis wants to merge 1 commit into
nervgh:masterfrom
davemaurakis:feature/async-filters

Conversation

@davemaurakis

Copy link
Copy Markdown

r? @nervgh

related to #235 & #180

@matthillman

Copy link
Copy Markdown

👍

@kuntsali

Copy link
Copy Markdown

@brownbathrobe Hi, brownbathrobe! I want to use your changes in pull request to implement height and width filter. Can you provide some example of filter usage or it can be used as usual? Thanks

@davemaurakis

Copy link
Copy Markdown
Author

@kuntsali - You should be able to use the filters as normal, but in the case of height/width you'll want the filter to return a promise. Here's an example that filters out folders:

uploader.filters.push({
  name: "rejectFolder",
  fn: function (item) {
    var deferred = $q.defer();
    function accept () { deferred.resolve(); }
    function reject () { deferred.reject(); }

    if (uploader.isHTML5) {
      var reader = new FileReader();
      /* file can be read successfully */
      reader.onloadstart = function () {
        accept();
        reader.onerror = null;
        reader.abort();
      };
      /* file can not be read and is likely a folder */
      reader.onerror = function () {
        reject();
      };
      /* try to read the file item */
      reader.readAsArrayBuffer(item);
    } else {
      accept();
    }
    return deferred.promise;
  }
});
@kuntsali

kuntsali commented Mar 2, 2015

Copy link
Copy Markdown

@brownbathrobe - Thank you!

@markslemko

Copy link
Copy Markdown

+1

@nervgh nervgh added this to the 2.0.0 milestone Jul 28, 2015
nervgh added a commit that referenced this pull request Nov 29, 2016
@nervgh

nervgh commented Nov 29, 2016 •

Copy link
Copy Markdown
Owner

Since 2.4.0 we can use sync and async filters. See an example.

The async filters require angular >=1.2.0.

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

Labels

None yet

5 participants