there is no image import { Text, View, Image, Pressable } from 'react-native'; import {…
- User
there is no image import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import { useNavigation } from '@react-navigation/native'; import {firebase} from '../Firebase/firebase'; import 'firebase/compat/storage'; import 'firebase/compat/firestore'; import React, {useState, useEffect} from 'react';
export default function PastMK() { const navigation = useNavigation(); const [pastMKList, setPastMKList]=useState([]);
useEffect(()=>{ const fetchData = async ()=>{ try{ const PastMKRef=firebase.firestore().collection('PastMK'); const snapshot =await PastMKRef.get(); const pastMKList=snapshot.docs.map((doc)=>{ const data =doc.data(); return{ id:doc.id, name:data.name, image:data.image, description:data.description, date:data.date }; }); setPastMKList(pastMKList); }catch(error){ console.log('Error fetching PastMK:', error); } }; fetchData(); },[]);
return ( {pastMKList.map((pastMK)=>( {pastMK.name} {pastMK.date.toDate().toLocaleDateString('ru-RU',{ day:'numeric', month:'long', year:'numeric' })} {pastMK.description} <Pressable style={gStyle.PastMKreadMore} onPress={()=>navigation.navigate('PastMKInfo')}> Читать далее
))} </View>); }
- Assistant
As an AI language model, I don't have the image referred to in the code. Can you provide more context or information on what's the issue or what you want to achieve?
- User
i need to show from my storage firebase image it shows everything except for images
- Assistant
If you're unable to show the images from Firebase storage, then there may be a few reasons for that. Here are some things you can try:
-
Verify that you have read permissions set up correctly for your Firebase storage. You can do this by going to the Firebase console and checking the rules for your storage bucket.
-
Check that the image URL in your Firebase database or Firestore is correct and that it points to the correct location in your Firebase storage.
-
Make sure that you have the correct security settings in your app to access external resources like Firebase storage. For example, on Android, you need to add the INTERNET and ACCESS_NETWORK_STATE permissions to your app's manifest file.
-
Verify that the image is actually getting uploaded to Firebase storage by checking the storage bucket in the Firebase console.
-
Try using a different image and see if it shows up. If a different image works, then the issue might be with the image file itself.
Additionally, make sure that you're using the correct Image source format and that the image size and dimensions are appropriate for the container where you're trying to display it.
-
- User
rules_version = '2';
service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read: if true; // allow all users and guests to read allow write: if request.auth != null && request.auth.uid == "qwMGcoF1V9WTDgpcWzaf3Rp9t9o1"; // allow only authenticated admin user to write } } }
- Assistant
Your security rules for Firestore seem to allow anyone to read your database. If your intent is to allow anyone to read your database, then your current rules are sufficient and there should be no issue retrieving images from Firebase storage.
However, if you only want authenticated users to read your database, you should update your rules to reflect that. You may want to try updating your rules as follows:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if false; // don't allow reads or writes by default } match /PastMK/{document} { allow read: if request.auth != null; // allow authenticated users to read allow write: if request.auth != null && request.auth.uid == "qwMGcoF1V9WTDgpcWzaf3Rp9t9o1"; // allow only authenticated admin users to write } } }In this example, I have added a new
matchblock specifically for thePastMKcollection, which requires authentication to read but only allows the designated admin user to write. All other reads and writes to your Firestore database are disallowed. - User
no, i need to show images to everyone, this image displays in other collection but not in pastmk
- Assistant
In that case, your Firestore security rules should allow all users to read your data, including images from Firebase storage. Your current rules already allow that, so there should be no issue with retrieving images from Firebase storage.
If images are not loading in the
PastMKcollection, then the issue may be with the image URLs stored in your Firebase database. Make sure that theimagefield for eachPastMKdocument correctly points to the URL of the image you're trying to display.You may also want to check that the image exists in your Firebase storage and that it has the correct permissions for anyone (not just authenticated users) to read it. You can do this by going to the Firebase console and checking the permissions for the image in your storage bucket.
Finally, you should make sure that you're using the correct Image source format in your React Native code. Check that the
uriproperty for each image is set to the correct URL for the image in Firebase storage. If the image is stored in a subfolder of your Firebase storage bucket, make sure to include the full path to the image in theuriproperty. - User
import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import { useNavigation } from '@react-navigation/native'; import {firebase} from '../Firebase/firebase'; import 'firebase/compat/storage'; import 'firebase/compat/firestore'; import React, {useState, useEffect} from 'react';
export default function PastMK() { const navigation = useNavigation(); const [pastMKList, setPastMKList]=useState([]);
- Assistant
If you can't see the image displayed in your app, then there may be a few things you can try:
-
Verify that the image URL in your Firestore database is correctly formatted and that it points to the correct location in your Firebase storage. You can check this by going to the Firebase console and checking the URL for the image you're trying to display.
-
Make sure that the security rules for your Firebase storage allow anyone (not just authenticated users) to read the image. You can check this in the Firebase console by going to your storage bucket, clicking on the
Rulestab, and making sure that everyone has read access. -
Check that your React Native app has the necessary permissions to read from external resources like Firebase storage. On Android, you need to add the INTERNET and ACCESS_NETWORK_STATE permissions to your app's
AndroidManifest.xmlfile.
-
- User
i have created new folder in my storage and named it PastMK and uploaded there an image and as image i use field like string adding a path to img like this "PastMK/some.png"
- Assistant
You've created a new folder in your Firebase storage and uploaded an image there, which is a good start. And when you set the
imagefield of yourPastMKdocument to a string like"PastMK/some.png", you're telling your app to look in thePastMKfolder in Firebase storage for thesome.pngimage.However, you also need to make sure that the security rules for your Firebase storage allow anyone to read from the
PastMKfolder. You can do this by adding a new rule to your storage security rules, like this:service firebase.storage { match /b/{bucket}/o { // ... // Allow anyone to read from the PastMK folder match /PastMK/{allPaths=**} { allow read; } } }This rule allows anyone to read any file in the
PastMKfolder. Make sure to update the bucket name ({bucket}) to the name of your Firebase storage bucket.Once you've updated your storage rules, make sure to publish the changes to ensure that they take effect. Then try reloading your app to see if the image displays correctly.