Hello,I am trying to solve a couple of errors below
getMyImage: [ReferenceError: Property ‘images’ doesn’t exist] ERROR
Error fetching image: [ReferenceError: Property ‘images’ doesn’t
exist] ERROR getMyImage: [FirebaseError: Firebase Storage: Object
‘n6gUmMX8doMgSBYEBQuBPMmRCqI2/image.jpeg’ does not exist.
(storage/object-not-found)] LOG 書き込み開始:
https://sayhellotobike-native-ios-default-rtdb.firebaseio.com
n6gUmMX8doMgSBYEBQuBPMmRCqI2 35.52398970747676 139.4505982399833 LOG
処理を送りました。
1.I could save my image
export const saveImage = async (userData, userId) => {
try {
const imageUri = userData.image;
const imageName = imageUri.split('/').pop(); // 画像名を取得
const type = imageUri.split('.').pop(); // ファイルの種類を取得
const mountainsRef = ref(storage, `${userId}/image`);
const response = await fetch(imageUri);
const blob = await response.blob();
let snapshot = await uploadBytes(mountainsRef, blob);
console.log("Firestoreに画像情報を保存しました。",snapshot);
// アップロードした画像のURLを取得
const downloadURL = await getDownloadURL(mountainsRef);
console.log('Download URL: ', downloadURL);
// Firestoreに画像情報を保存
const userDocRef = doc(firestore, `users/${userId}`);
await setDoc(userDocRef, { imageUrl: downloadURL }, { merge: true });
console.log("Firestoreに画像情報を保存しました。", snapshot);
} catch (e) {
console.error("Error adding document: ", e);
} finally {
console.log("saveImage");
}
};
my Url is gs://sayhellotobike-native-ios.appspot.com/n6gUmMX8doMgSBYEBQuBPMmRCqI2
user_id becomes folder
the image i saved is image.jpeg
3.
i can pick up userId collectly
export const getMyImage = async (userId) => {
try {
const userDocRef = ref(storage,`${userId}/image.jpeg`);
getDownloadURL(userDocRef).then((url) => {
// `url` is the download URL for 'images/stars.jpg'
console.log("TEST",url)
// This can be downloaded directly:
const xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = (event) => {
const blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
})
.catch((error) => {
console.error("getMyImage: ", error);
throw error;
});
return images;
} catch (error) {
console.error("getMyImage: ", error);
throw error;
}
};
I hope to download from storage
thank you