The "storage/object-not-found" error occurs when Firebase Storage cannot locate a file at the path you're trying to access. This happens when files are deleted, paths are incorrect, or uploads haven't completed. Fix it by verifying the file exists, checking your path syntax, and handling upload timing.
The "storage/object-not-found" error indicates that Firebase Storage cannot locate a file at the path you're trying to access. This is one of the most common Firebase Storage errors and occurs when the SDK attempts operations like getDownloadURL(), getMetadata(), or delete() on a reference that points to a non-existent object. Firebase Storage uses a hierarchical path structure similar to a file system. When you create a reference like ref(storage, "images/profile.jpg"), Firebase expects a file to exist at that exact path in your Storage bucket. If the file was never uploaded, was deleted, or the path contains typos or case mismatches, the operation will fail with this error. Unlike file systems, Firebase Storage paths are case-sensitive and exact. A file at "users/123/photo.jpg" is completely different from "Users/123/photo.jpg" or "users/123/Photo.jpg". Additionally, this error can occur during race conditions where code tries to access a file before an upload completes, or when relying on stale references after deletions.
Open the [Firebase Console](https://console.firebase.google.com/), navigate to Storage, and manually browse to the path where you expect the file to be located.
Check:
- Does the file exist at the exact path you're using?
- Is the filename spelled correctly (case-sensitive)?
- Are there any unexpected folder structures?
If the file doesn't exist, you'll need to upload it first or fix your upload logic before trying to access it.
Ensure your code uses the correct path syntax. Firebase Storage paths should NOT start with a forward slash:
// Correct - no leading slash
const correctRef = ref(storage, "users/123/profile.jpg");
// Incorrect - leading slash creates different path
const incorrectRef = ref(storage, "/users/123/profile.jpg");Verify the path matches exactly:
import { getStorage, ref, getDownloadURL } from "firebase/storage";
const storage = getStorage();
const fileRef = ref(storage, "images/photo.jpg");
console.log("Full path:", fileRef.fullPath);
console.log("Bucket:", fileRef.bucket);
try {
const url = await getDownloadURL(fileRef);
console.log("Success:", url);
} catch (error) {
console.error("Error accessing file:", error.code, error.message);
console.error("Attempted path:", fileRef.fullPath);
}Compare the logged path with what you see in the Firebase Console.
Use the listAll() method to see what files actually exist in a directory:
import { getStorage, ref, listAll } from "firebase/storage";
const storage = getStorage();
const listRef = ref(storage, "users/123");
try {
const result = await listAll(listRef);
console.log("Files in directory:");
result.items.forEach((itemRef) => {
console.log(" -", itemRef.fullPath);
});
console.log("\nSubdirectories:");
result.prefixes.forEach((folderRef) => {
console.log(" -", folderRef.fullPath);
});
} catch (error) {
console.error("Error listing files:", error);
}This helps identify typos, unexpected folder structures, or files in different locations than expected.
If you're trying to access a file immediately after uploading, ensure the upload promise resolves first:
import { getStorage, ref, uploadBytes, getDownloadURL } from "firebase/storage";
const storage = getStorage();
const fileRef = ref(storage, "uploads/document.pdf");
async function uploadAndGetURL(file) {
try {
// Wait for upload to complete
const snapshot = await uploadBytes(fileRef, file);
console.log("Upload successful:", snapshot.metadata.fullPath);
// Now safe to get download URL
const downloadURL = await getDownloadURL(fileRef);
console.log("Download URL:", downloadURL);
return downloadURL;
} catch (error) {
console.error("Upload or URL retrieval failed:", error);
throw error;
}
}For upload tasks with progress monitoring:
import { uploadBytesResumable, getDownloadURL } from "firebase/storage";
const uploadTask = uploadBytesResumable(fileRef, file);
uploadTask.on("state_changed",
(snapshot) => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log("Upload is " + progress + "% done");
},
(error) => {
console.error("Upload failed:", error);
},
async () => {
// Upload completed successfully
const downloadURL = await getDownloadURL(uploadTask.snapshot.ref);
console.log("File available at:", downloadURL);
}
);Sometimes restrictive security rules return "object-not-found" instead of "unauthorized". Review your Firebase Storage rules:
In the Firebase Console, go to Storage → Rules and verify read access is allowed:
// Example: Allow authenticated users to read their own files
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /users/{userId}/{allPaths=**} {
allow read: if request.auth != null && request.auth.uid == userId;
allow write: if request.auth != null && request.auth.uid == userId;
}
}
}For testing purposes only (NOT for production):
// Allow public read access - USE ONLY FOR TESTING
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read: if true;
allow write: if request.auth != null;
}
}
}Deploy the rules and test again. If the error disappears, the issue was permissions, not a missing file.
If your project uses multiple storage buckets, ensure you're referencing the correct one:
import { getStorage, ref } from "firebase/storage";
// Default bucket
const defaultStorage = getStorage();
// Specific bucket
const customStorage = getStorage(app, "gs://my-other-bucket.appspot.com");
// Create reference in the correct bucket
const fileRef = ref(customStorage, "path/to/file.jpg");Check the Firebase Console to see which bucket contains your file, especially if you recently migrated or have legacy and new buckets (.appspot.com vs .firebasestorage.app).
For production applications, implement robust error handling that distinguishes between object-not-found and other storage errors:
import { getDownloadURL, ref } from "firebase/storage";
async function safeGetDownloadURL(path) {
const storage = getStorage();
const fileRef = ref(storage, path);
try {
return await getDownloadURL(fileRef);
} catch (error) {
if (error.code === "storage/object-not-found") {
console.warn(`File not found: ${path}`);
// Return placeholder or trigger upload
return "/default-image.png";
} else if (error.code === "storage/unauthorized") {
console.error("Permission denied:", path);
throw new Error("You don't have access to this file");
} else {
console.error("Unexpected storage error:", error);
throw error;
}
}
}Database consistency: If you store file paths in Firestore or Realtime Database, ensure you update or delete those references when files are deleted:
import { deleteObject, ref } from "firebase/storage";
import { doc, deleteField, updateDoc } from "firebase/firestore";
async function deleteFileAndReference(userId, fileName) {
const storage = getStorage();
const db = getFirestore();
const fileRef = ref(storage, `users/${userId}/${fileName}`);
const userDoc = doc(db, "users", userId);
try {
// Delete file from storage
await deleteObject(fileRef);
// Remove reference from Firestore
await updateDoc(userDoc, {
profileImage: deleteField()
});
console.log("File and reference deleted successfully");
} catch (error) {
console.error("Deletion failed:", error);
throw error;
}
}October 2024 bucket migration: Firebase introduced new bucket URLs (.firebasestorage.app). If you're using refFromURL() with hardcoded bucket URLs, verify you're using the correct format shown in your Firebase Console. The old .appspot.com format still works for existing projects, but new projects use the new domain.
Flutter/React Native considerations: In mobile frameworks, ensure you're using the correct bucket reference method. Some SDKs had bugs where refFromURL() was required instead of the simpler ref() constructor when working with non-default buckets.
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage
auth/missing-uid: User ID identifier required
How to fix "auth/missing-uid: User ID identifier required" in Firebase
auth/invalid-argument: Invalid parameter passed to method
How to fix "auth/invalid-argument: Invalid parameter passed to method" in Firebase