【发布时间】:2019-04-01 05:57:37
【问题描述】:
我想让用户在同一个活动中注册并上传一张图片,所以姓名和电子邮件等数据将进入 firestore,而图片将进入存储桶,目前,我能够实现这两个功能,但分开,所以我有点坚持的是如何将数据和图像链接在一起,以便我以后可以检索它们。我也想用 Vuex 来完成。下面的代码解释了我如何将数据和图像分别从我的 .vue 组件发送到 firestore 和 storage
import { storage } from '../firebase/init.js'
import firebase from 'firebase'
export default {
data(){
return {
email: '',
password: '',
image: null
}
},
methods: {
signUp(){
firebase.auth().createUserWithEmailAndPassword(this.email, this.password)
.then(response => {
let user = {
id: response.user.id,
email: response.user.email
}
//here i want to do something to link this user to the upload image event below
})
},
uploadFile(e){
const file = e.target.files[0];
storage.ref('images/'+ file.name).put(file)
.then(response => {
console.log(response)
})
.catch(err => console.log(err))
}
}
请在下方留言以作进一步说明,在此先感谢
【问题讨论】:
-
为什么不在存储引用路径中包含用户id?喜欢
images/${userId}/${file.name} -
实际上我确实尝试过它并且它有效,所以现在我将信息发送到我的 Firestore 集合,然后上传带有响应 ID 的图像,在此处检查代码 codesandbox,现在,你有任何想法如何在应用程序中检索和呈现它吗?无论如何谢谢:)
标签: firebase vue.js firebase-authentication google-cloud-firestore vuex