我正在尝试从 Firebase Storage 检索图像 url,然后使用该 url 设置图像。但是,似乎我正在使用当前代码将 src 设置为未定义的值:
这是我用来从 Firebase 存储中检索的函数
import {Firebase,
FirebaseAuth,
FirebaseDatabase,
FirebaseStorage} from '../Initialize'
export function getProfilePictureUrl(uid, callback, onErrorCallback) {
var pathReference = FirebaseStorage.ref('profiles/' + uid + '/profilePicture.jpeg');
pathReference.getDownloadURL().then((url) => {
callback(url);
}).catch((error) => {
onErrorCallback(error);
});
}
Run Code Online (Sandbox Code Playgroud)
我从使用如下函数的 React 组件调用它:
render() {
let profilePictureUrl = getProfilePictureUrl(uid, (url) => {
console.log(url); // The console.log(url) returns a valid and working url for the image. So I know my imports are correct
return url;
},
(error) => …Run Code Online (Sandbox Code Playgroud)