-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Needs: Author FeedbackIssues awaiting author feedbackIssues awaiting author feedbackclosed-by-botemulators: storageno-recent-activitytype: bug
Description
[REQUIRED] Environment info
Firebase Version: ^11.4.0
firebase-tools: Version not provided (please run firebase --version and include the output)
Platform: MacOS, iOS (iPad with Expo Go)
[REQUIRED] Test case
// Recipe service implementation using Firebase
import { collection, addDoc, getDocs, query, orderBy, Timestamp } from 'firebase/firestore';
import { getStorage, ref, uploadBytes, getDownloadURL } from 'firebase/storage';
import { db } from './firebase';
// Interface definitions and service implementation as provided in the code snippet
// (Keeping the relevant parts for the image upload issue)
const recipeService = {
uploadRecipe: async (recipeData: NewRecipe, imageUri: string) => {
try {
const storage = getStorage();
const imageRef = ref(storage, `recipes/${Date.now()}_${recipeData.userId}.jpg`);
const response = await fetch(imageUri);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const blob = await response.blob();
if (!blob) {
throw new Error('Failed to create blob from image');
}
const metadata = {
contentType: 'image/jpeg',
customMetadata: {
userId: recipeData.userId,
recipeTitle: recipeData.title
}
};
await uploadBytes(imageRef, blob, metadata);
// ... rest of the implementation
} catch (error) {
console.error('Error in recipe upload:', error);
throw error;
}
}
};[REQUIRED] Steps to reproduce
- Initialize a React Native project with Firebase
- Set up Firebase Storage
- Attempt to upload an image using the recipe service implementation above
- The error occurs during the
uploadBytesoperation
[REQUIRED] Expected behavior
The image should be successfully uploaded to Firebase Storage, and the image URL should be returned for storing in Firestore along with the recipe data.
[REQUIRED] Actual behavior
The upload fails with the following error:
Converting image to blob...
(NOBRIDGE) LOG Uploading image to Firebase Storage...
(NOBRIDGE) ERROR Error in recipe upload: [FirebaseError: Firebase Storage: An unknown error occurred, please check the error payload for server response. (storage/unknown)]
Firebase rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
Additional context
- Environment: React Native with Expo Go
- Testing Device: iPad
- The issue has persisted for a week despite trying solutions from Stack Overflow
- The blob creation appears successful, but the upload to Firebase Storage fails
- I uploaded a profile picture image when I sign up and that works well and even displayes on my profile page
Attempted solutions
- Tested on Expo Go on iPad
- Implemented solutions found on Stack Overflow (https://stackoverflow.com/questions/70052479/firebase-storage-an-unknown-error-occurred-please-check-the-error-payload-for)
-
- Image size is about 921KB
Metadata
Metadata
Assignees
Labels
Needs: Author FeedbackIssues awaiting author feedbackIssues awaiting author feedbackclosed-by-botemulators: storageno-recent-activitytype: bug