Skip to content

cannot upload images in ios simulator/real device due to firebase error #8309

@Pavilion-devs

Description

@Pavilion-devs

[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

  1. Initialize a React Native project with Firebase
  2. Set up Firebase Storage
  3. Attempt to upload an image using the recipe service implementation above
  4. The error occurs during the uploadBytes operation

[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

  1. Tested on Expo Go on iPad
  2. Implemented solutions found on Stack Overflow (https://stackoverflow.com/questions/70052479/firebase-storage-an-unknown-error-occurred-please-check-the-error-payload-for)
    1. Image size is about 921KB

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions