Firebase Storage에서 이미지 URL을 검색하고 해당 URL로 이미지를 설정하려고합니다.Firebase Storage에서 사진을 불러 와서
이 내가 중포 기지 저장 장치에서 검색 할 수 사용하고 내 기능이
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);
});
}
내가 구성 부품 반작용에서 호출 : 그러나, 내 현재 코드로 정의되지 않은 값으로 SRC를 설정하고 보인다
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) => {
console.log(error.code);
return "";
})
return (
<img
src={profilePictureUrl}
/>
);
}
ProfilePictureUrl이 정의되지 않은 이미지이므로 제대로로드되지 않습니다.
I의이()와 테스터 내부 렌더링 만들려고 사용했을
render() {
if(profilePictureUrl !== undefined) {
console.log("defined");
}
else {
console.log("undefined");
}
// returns 'undefined'
}
그리고 함수가 정의되지 않은 값을 리턴하는 것을 나타내는 다른 응답을 기록되고 있었다. Firebase의 비동기 성질과 관련이 있다는 의심이 들지만, 어떻게 해결해야할지 모르겠다. 구글을 통해 찾을 수 React-Native: Download Image from Firebase Storage