I am a newbie to firebase and Javascript.
(我是Firebase和Javascript的新手。)
How do I change the file name to user's uid and save it to storage?
(如何将文件名更改为用户的uid并将其保存到存储中?)
And I want to upload a file after successful registration. (我想在成功注册后上传文件。)
Should I write a function in createUserWithEmailAndPassword or onAuthStateChanged? (我应该在createUserWithEmailAndPassword或onAuthStateChanged中编写函数吗?)
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var file = evt.target.files[0];
var metadata = {
'contentType': file.type
};
var storage_ref = storage.ref();
storage_ref.child('userImages/' + user.uid).put(file, metadata).then(function(snapshot) {
snapshot.ref.getDownloadURL().then(function(url) {
console.log('File available at', url);
profile_url = url;
});
}).catch(function(error) {
console.error('Upload failed:', error);
});
} // handleFileSelect
document.getElementById('input_img').addEventListener('change',handleFileSelect, false);
ask by Li Optt translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…