I’m attempting to submit pictures to firebase Expo crash with none log with Expo Picture Picker. However not everytime. Typically it really works excellent, however generally it quits with none error log. I’m new and might be pleased if anybody helps. I attempted a number of issues however outcome shouldn’t be change. Right here is my code:
import * as ImagePicker from 'expo-image-picker';
import { getFirestore, getDocs, assortment, addDoc } from "firebase/firestore";
import { getDownloadURL, getStorage, ref, uploadBytes } from "firebase/storage"
import { app } from '../../firebaseConfig';
export default operate AddPostScreen() {
const storage = getStorage();
const [images, setImages] = useState([]);
const db = getFirestore(app);
const [uploading, setUploading] = useState(false);
const [selectedImages, setSelectedImages] = useState<string[]>([]);
const [loading, setLoading] = useState(false);
const pickImages = async () => {
let outcome = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Photos,
allowsMultipleSelection: true,
allowsEditing: false,
high quality: 0,
base64: true,
});
if (!outcome.canceled) {
const uris = outcome?.belongings.map((picture) => picture.uri) ?? [];
setSelectedImages(uris);
}
};
const onSubmitMethod = async (values: any) => {
setLoading(true);
values.picture = selectedImages;
values.postId = Date.now().toString();
const imagePromises = selectedImages.map(async (uri, index) => {
const response = await fetch(uri);
const blob = await response.blob();
const imageName = `userPost/${Date.now()}_${index}`; // Distinctive picture title
const storageRef = ref(storage, imageName);
setUploading(true); // Begin importing
await uploadBytes(storageRef, blob);
setUploading(false); // End importing
const downloadURL = await getDownloadURL(storageRef);
return downloadURL;
});
const imageUrls = await Promise.all(imagePromises);
values.pictures = imageUrls;
values.userName = consumer.fullName;
values.userEmail = consumer.primaryEmailAddress.emailAddress;
values.userImage = consumer.imageUrl;
console.log('Photos uploaded:', imageUrls);
// Add the doc with the picture URLs to the gathering
const docRef = await addDoc(assortment(db, 'UserPost'), values);
if (docRef.id) {
setLoading(false);
Alert.alert('Təbriklər!', 'Elan uğurla əlavə edildi!')
// Clear the chosen pictures after add
setSelectedImages([]);
}
};
return (