Ember.js ember-plupload 拖放
Ember.js ember-plupload drag&drop
我想创建一个拖放上传文件 ember.js 应用程序,我正在尝试使用 ember-plupload,但我无法使 plupload 工作,这是我的代码:
{{#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}}
这是plupload的示例模板。还有一条路线:
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();
});
}
}
});
再次采样。终于有结果了,页面
Upload Images
Drag and drop images onto this area to upload them or Add an Image.
但是我无法将任何东西拖到上面。还有一个 firebug 日志:
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
在那种情况下我能做什么?你好,拉法尔
我已经在作者的github页面上创建了一个问题,问题很快就解决了,所以这个案例就结案了,感谢Tim的大力支持。
ember-plupload 有一个新的工作版本。
你好,拉法尔
我想创建一个拖放上传文件 ember.js 应用程序,我正在尝试使用 ember-plupload,但我无法使 plupload 工作,这是我的代码:
{{#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}}
这是plupload的示例模板。还有一条路线:
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();
});
}
}
});
再次采样。终于有结果了,页面
Upload Images
Drag and drop images onto this area to upload them or Add an Image.
但是我无法将任何东西拖到上面。还有一个 firebug 日志:
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
在那种情况下我能做什么?你好,拉法尔
我已经在作者的github页面上创建了一个问题,问题很快就解决了,所以这个案例就结案了,感谢Tim的大力支持。
ember-plupload 有一个新的工作版本。
你好,拉法尔