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 tutorial to trigger from submit #144

Open
alvarouribe opened this issue Jan 31, 2017 · 1 comment
Open

Add tutorial to trigger from submit #144

alvarouribe opened this issue Jan 31, 2017 · 1 comment

Comments

@alvarouribe
Copy link

Guys could you create a readme area to explain how to upload only when a user clics on a submit button / action ?

@kernel-io
Copy link

kernel-io commented Mar 2, 2017

It's relatively simple

use file-upload component

import EmberUploader from 'ember-uploader'
export default EmberUploader.FileField.extend({});

add event handler in template

file-upload filesDidChange=(route-action 'filesChanged')

in route / controller handle the event, the first argument will be the files list

filesChanged(files) {
      set(this, 'currentModel', files)
}

then just create an uploader in your save handler, whatever that may be, mine is a ember-concurrency task

uploadTask: task(function*() {
    const files = get(this, 'currentModel')
    const uploader = EmberUploader.Uploader.create({
      url: `${ENV.APP.apiUrl}/import/users`
    });

    if (!isEmpty(files)) {
      yield uploader.upload(files[0]).then( () => {
        this.notify.success({ title: 'Data Imported Successfully' })
        this.transitionTo('integrations.index')
      }).catch( error => {
        this.notify.error({ title: 'Data Import Error', blurb: error.message })
      })
    }

  })

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

2 participants