Mat*_*ner 1 ember.js firebase emberfire firebase-storage
我对Ember和EmberFire比较陌生.我正在开发一个客户/徽标管理应用程序.我目前已按预期运行Firebase身份验证和Firebase数据.当我将徽标上传到Firebase存储空间时,出现此错误:
Uncaught Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp(). firebase.js:30
Run Code Online (Sandbox Code Playgroud)
这是被调用的动作:
调节器
firebase: Ember.inject.service( 'firebase' ),
actions: {
createClient(){
let name = this.get( 'clientName' );
let image = document.getElementById( 'client-image' );
let storeName = name.replace( / /g, '' );
let storageRef = firebase.storage().ref();
let file = image.files[0];
let metadata = {
'contentType' : file.type
};
let uploadTask = storageRef.child( `uploads/${storeName}/${file.name}` ).put( file, metadata );
uploadTask.on( 'state_changed', null, function( error ){
console.error( 'Upload Failed:', error );
}, function(){
console.log( 'Uploaded', uploadTask.snapshot.totalBytes, 'bytes.' );
console.log( uploadTask.snapshot.metadata );
let uploadUrl = uploadTask.snapshot.metadata.downloadURLs[0];
console.log( 'File available at ', url );
let client = this.store.createRecord( 'client', {
name: name,
image: uploadUrl,
isActive: false,
timestamp: new Date().getTime()
} );
client.save();
} );
// Tell the route to hide the client form.
this.send( 'hideAddClientForm' );
}
}
Run Code Online (Sandbox Code Playgroud)
模板
<div id="new-overlay" class="overlay" {{action "hideAddClientForm"}}></div>
<div id="newClient">
{{input type="text" id="client-name" placeholder="Client Name" value=clientName}}<br />
{{input type="file" id="client-image" value=clientImage}}
<div class="submitBtn" {{action "createClient"}}>Add Client</div>
</div>
Run Code Online (Sandbox Code Playgroud)
因此,简而言之,我如何访问EmberFire提供的Firebase参考,以便我可以调用快速入门中显示的"storage()"方法.如果无法访问该引用,是否必须创建另一个对Firebase的"非EmberFire"引用才能使用存储?我只是想上传一个.jpg.
确保您使用的是EmberFire 2.0.您可以通过该firebaseApp服务访问Firebase Storage API :
firebaseApp: Ember.inject.service(),
actions: {
doSomething() {
const storageRef = this.get('firebaseApp').storage();
}
}
Run Code Online (Sandbox Code Playgroud)
该firebaseApp服务是一个已经初始化的应用程序,不要与firebase服务混淆,该服务只是数据库引用(为了向后兼容而保留).
| 归档时间: |
|
| 查看次数: |
1290 次 |
| 最近记录: |