看我另一个帖子的回答
<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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
它只是有效。
如果您阅读下面链接中的答案,您将了解如何使用 emberjs 上传文件并保存到服务器:
在上面链接中“Toran Billups”提供的答案中,我从他的答案中复制了以下几行,将其保存到服务器:
var person = PersonApp.Person.createRecord({username: 'heyo', attachment: fileToUpload});
self.get('controller.target').get('store').commit()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13810 次 |
| 最近记录: |