lundi 6 novembre 2017

How to preform a component action rather than a route action in ember-file-upload

I am using the package http://ift.tt/2aQqktW

In their example, they call a route action to upload an image

             onfileadd=(route-action "uploadImage")}}

However I would like to instead call a component action

I tried doing

                 onfileadd="uploadImage"}}

and added the action in component:

uploadImage: function (file) {
  console.log(file);
  let self = this;
  RSVP.cast(Ember.$.get(ENV.APP.API_HOST + "/v1/teams/signed_url/")).then(function (response) {
    return file.upload(response.url, {
      data: response.credentials
    });
  }).then(function (response) {
    self.set('url', response.headers.Location);
  });
},

But I got the error:

Uncaught TypeError: Cannot read property 'uploadImage' of undefined

The action works as expected if I move it to route, but I need to update the correct properties in the component (that do not exist in the route)

Any idea what I can do to change that to a component function ?




Aucun commentaire:

Enregistrer un commentaire