7

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

有什么好的例子吗?

4

2 回答 2

5

从另一个线程查看我的答案

<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);
    }
  }
}

它只是工作。

于 2016-11-02T00:49:11.060 回答
2

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

使用 Ember 数据上传文件

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

var person = PersonApp.Person.createRecord({username: 'heyo', attachment: fileToUpload});

self.get('controller.target').get('store').commit()
于 2013-02-04T09:53:58.523 回答