0

https://github.com/RamanSharma100/react-firebase-file-management-system/issues/2#issuecomment-1666569161

firebase post error. I'm trying to connect to the firebase and I'm getting these errors. can someone please guide me with this issue?

I'm able to login and register a user even the backend is working fine, but the issue is the firebase storage.

I'm getting these errors:

connection.ts:81 POST https://firebasestorage.googleapis.com/v0/b/cloud-file-management-system.appspot.com/o?name=files%2FFT2YJy4lk3gTKb5ezJMH2fYPUrq1%2FNew%20Text%20Document.txt net::ERR_FAILED

Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com/v0/b/cloud-file-management-system.appspot.com/o?name=files%2FFT2YJy4lk3gTKb5ezJMH2fYPUrq1%2FNew%20Text%20Document.txt' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

connection.ts:81 POST https://firebasestorage.googleapis.com/v0/b/cloud-file-management-system.appspot.com/o?name=files%2FFT2YJy4lk3gTKb5ezJMH2fYPUrq1%2FNew%20Text%20Document.txt net::ERR_FAILED

Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com/v0/b/cloud-file-management-system.appspot.com/o?name=files%2FFT2YJy4lk3gTKb5ezJMH2fYPUrq1%2FNew%20Text%20Document.txt' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

1

It is because of CORS policy. You need to configure CORS policy in firebase storage you can do the same by following these steps:_

step1. Create cors.json file eg:-

[
  {
    "origin": ["http://localhost:3000"],
    "method": ["GET", "POST", "PUT", "DELETE"],
    "maxAgeSeconds": 4000,
    "responseHeader": ["Content-Type", "Authorization"]
  }
]

step2. Upload this configuration using firebase cli configure cli first if you haven't

bash command:-

Replace "cloud-file-management-system.appspot.com" with your specific firebase storage URL.

gsutil cors set cors.json gs://cloud-file-management-system.appspot.com

Aman Khan
  • 34
  • 2