Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 1.7 KB

File metadata and controls

76 lines (57 loc) · 1.7 KB

Firebase Storage CORS Fix for Social Media

If social media platforms can't access your Firebase Storage images, you may need to configure CORS.

Quick Fix

1. Install Firebase CLI (if not already installed)

npm install -g firebase-tools

2. Login to Firebase

firebase login

3. Initialize Firebase in your project (if not already done)

firebase init

4. Create CORS configuration file

Create a file called cors.json in your project root:

[
  {
    "origin": ["*"],
    "method": ["GET", "HEAD"],
    "maxAgeSeconds": 3600
  }
]

5. Apply CORS configuration

gsutil cors set cors.json gs://your-firebase-storage-bucket

Replace your-firebase-storage-bucket with your actual bucket name (e.g., blog-d85ac.appspot.com)

Alternative: Use Cloudinary

If CORS issues persist, consider using Cloudinary for image hosting:

1. Sign up for Cloudinary

2. Update image upload logic

// In createBlog.jsx, replace Firebase upload with Cloudinary
const uploadToCloudinary = async (file) => {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('upload_preset', 'your_upload_preset');
  
  const response = await fetch('https://api.cloudinary.com/v1_1/your_cloud_name/image/upload', {
    method: 'POST',
    body: formData
  });
  
  const data = await response.json();
  return data.secure_url;
};

Test After Fix

  1. Upload a new blog post with thumbnail
  2. Test the social media preview
  3. Wait 24-48 hours for cache refresh

Emergency Fallback

If all else fails, use the Unsplash fallback image which is already configured and working.