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

reset plupload queue if server responds with error #131

Open
rinoldsimon opened this issue Aug 4, 2018 · 1 comment
Open

reset plupload queue if server responds with error #131

rinoldsimon opened this issue Aug 4, 2018 · 1 comment

Comments

@rinoldsimon
Copy link

rinoldsimon commented Aug 4, 2018

hbs

    {{#pl-uploader for="upload-image" extensions="jpg jpeg" max-file-size="5000000" onfileadd="uploadImage" as |queue|}}
      {{#if queue.length}}
        Uploading...{{queue.progress}}%
      {{else}}
        <a id="upload-image">Add an Image.</a>
      {{/if}}
    {{/pl-uploader}}

js

    uploadImage(file) {
      var image = this.store.createRecord('image', {
        filename: get(file, 'name'),
        filesize: get(file, 'size')
      });

      file.read().then(function (url) {
        if (get(image, 'url') == null) {
          set(image, 'url', url);
        }
      });

      file.upload('/api/images/upload').then(function (response) {
        set(image, 'url', response.headers.Location);
        return image.save();
      }, function () {
        image.rollback();
      });
    }

if there is any error from api side Uploading...{{queue.progress}}% in hbs is still shown. I want to reset the queue so that if there is an error the hbs view changes to else part (i.e) <a id="upload-image">Add an Image.</a>

@rinoldsimon rinoldsimon changed the title reset plupload queue of server responds with error reset plupload queue if server responds with error Aug 4, 2018
@rinoldsimon
Copy link
Author

can be achieved using file.destroy() ?

    file.upload('/api/images/upload').then(function (response) {
       set(image, 'url', response.headers.Location);
       return image.save();
     }, function () {
       file.destroy()
       image.rollback();
     });

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

No branches or pull requests

1 participant