Search code examples
javascriptember.jsdrag-and-dropplupload

Ember.js ember-plupload drag&drop


I want to create a drag & drop upload file ember.js app, I'm trying to use ember-plupload, but I can't make the plupload work, here is my code:

{{#pl-uploader for="upload-image" extensions="jpg jpeg png gif" onfileadd="uploadImage" as |queue dropzone|}}
  <div class="dropzone" id={{dropzone.id}}>
    {{#if dropzone.active}}
      {{#if dropzone.valid}}
        Drop to upload
      {{else}}
        Invalid
      {{/if}}
    {{else if queue.length}}
      Uploading {{queue.length}} files. ({{queue.progress}}%)
    {{else}}
      <h4>Upload Images</h4>
      <p>
        {{#if dropzone.enabled}}
          Drag and drop images onto this area to upload them or
        {{/if}}
        <a id="upload-image">Add an Image.</a>
      </p>
    {{/if}}
  </div>
{{/pl-uploader}}
{{outlet}}

It's the sample template from plupload. And a route:

import Ember from "ember";

const get = Ember.get;
const set = Ember.set;

export default Ember.Route.extend({

  actions: {
    uploadImage: function (file) {
      var product = this.modelFor('product');
      var image = this.store.createRecord('image', {
        product: product,
        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();
      });
    }
  }
});

Sample again. Finally there is the result, the page

Upload Images

Drag and drop images onto this area to upload them or Add an Image.

But I can't drag anything onto it. And a firebug log:

Instantiating FileInput...
Trying runtime: html5
Object {accept=[1], name="file", multiple=true, ...}
default mode: browser
selected mode: false
Runtime 'html5' failed to initialize
Trying runtime: html4
Object {accept=[1], name="file", multiple=true, ...}
default mode: browser
selected mode: false
Runtime 'html4' failed to initialize
Trying runtime: flash
Object {accept=[1], name="file", multiple=true, ...}
select_multiple: true (compatible modes: null)
drag_and_drop: true (compatible modes: null)
default mode: client
send_browser_cookies: false (compatible modes: client)
select_file: true (compatible modes: client)
selected mode: false
Runtime 'flash' failed to initialize
Trying runtime: silverlight
Object {accept=[1], name="file", multiple=true, ...}
select_multiple: true (compatible modes: null)
drag_and_drop: true (compatible modes: null)
default mode: browser
send_browser_cookies: false (compatible modes: client)
select_file: true (compatible modes: client)
Silverlight is not installed or minimal version (2.0.31005.0) requirement not met (not likely).
selected mode: false
Runtime 'silverlight' failed to initialize
Instantiating FileDrop...
Trying runtime: html5
Object {accept=[1], required_caps=Object, ...}
default mode: browser
selected mode: false
Runtime 'html5' failed to initialize
Trying runtime: html4
Object {accept=[1], required_caps=Object, ...}
default mode: browser
selected mode: false
Runtime 'html4' failed to initialize
Trying runtime: flash
Object {accept=[1], required_caps=Object, ...}
select_multiple: true (compatible modes: null)
drag_and_drop: true (compatible modes: null)
default mode: client
drag_and_drop: true (compatible modes: null)
send_browser_cookies: false (compatible modes: client)
select_file: true (compatible modes: client)
selected mode: false
Runtime 'flash' failed to initialize
Trying runtime: silverlight
Object {accept=[1], required_caps=Object, ...}
select_multiple: true (compatible modes: null)
drag_and_drop: true (compatible modes: null)
default mode: browser
drag_and_drop: true (compatible modes: null)
send_browser_cookies: false (compatible modes: client)
select_file: true (compatible modes: client)
Silverlight is not installed or minimal version (2.0.31005.0) requirement not met (not likely).
selected mode: false
Runtime 'silverlight' failed to initialize

What can I do in that case? Greetings, Rafał


Solution

  • I've created an issue on the author's github page, and the problem was solved immediately, so the case is closed, and Thanks for Tim for a great support.

    There is a new, working version of ember-plupload.

    Greetings, Rafał