Firebase 给出错误:无法读取未定义的属性“ref”
2018-07-14
916
我想在 Firebase 存储中上传照片,一旦上传,就会在控制台上打印一个 downloadURL。 照片上传完美,没有任何问题,但在控制台中打印的不是 downloadURL,而是 undefined,并抛出一个错误,指出“TypeError:无法读取未定义的属性‘ref’”。
const file = $('#exampleInputFile').get(0).files[0]; // getting file to be uploaded
const name = (+new Date() + '-' + file.name); // creating filename with timestamp
const task = ref.child(name).put(file, {contentType: file.type}); //setting file
task.then( (snapshot) => console.log (snapshot.downloadURL))
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link -
${downloadURL}`);
// once done trying to get downloadURL against this upload
})
.catch(error => {
// Use to signal error if something goes wrong.
console.log(`Failed to upload file and get link - ${error}`);
});
//or throw and error in console
1个回答
save() {
this.storageref.child(this.file.name).put(this.file).then(snapshot => {
let image = snapshot.metadata.downloadURLs[0];
consol.log(image);
});
}
DVP SmartCreators Inc we make
2018-07-14