【问题标题】:How: File Upload with ember.js [closed]如何:使用 ember.js 上传文件 [关闭]
【发布时间】:2013-01-18 13:13:12
【问题描述】:

我想知道如何使用 ember.js 进行真正的文件上传(将文件保存到服务器)

有什么好的例子吗?

【问题讨论】:

标签: ember.js


【解决方案1】:

从另一个thread查看我的回答

<input
  multiple="true"
  onchange={{action "upload"}}
  accept="image/png,image/jpeg,application/pdf"
  type="file"
/>

actions: {
  upload: function(event) {
    const reader = new FileReader();
    const file = event.target.files[0];
    let imageData;

    // Note: reading file is async
    reader.onload = () => {
      imageData = reader.result;
      this.set(data.image', imageData);

      // additional logics as you wish
    };

    if (file) {
      reader.readAsDataURL(file);
    }
  }
}

它只是工作。

【讨论】:

    【解决方案2】:

    如果您阅读下面链接中的答案,您将了解如何使用 emberjs 进行文件上传和保存到服务器:

    File upload with Ember data

    在上面链接中“托兰·比卢普斯”提供的答案中,我从他的答案中复制的以下几行将保存到服务器:

    var person = PersonApp.Person.createRecord({username: 'heyo', attachment: fileToUpload});
    
    self.get('controller.target').get('store').commit()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-21
      • 2013-08-27
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多