Monday, February 26, 2018

How to Configure Firebase Cloud Storage bucket for cross-origin access (CORS)

If you have ever tried to download data stored in Firebase Cloud Storage directly in your browser you may have come across this error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access

In order to fix this error you will need to run through a couple of steps to configure Firebase Cloud Storage for CORS. The following steps can be taken in order to do this:

GSUtil

There are at least two approaches to configure the cloud storage with GSUtil:

Cloud shell within Google Cloud Platform

You can manage Compute Engine resources like virtual machine instances using the gcloud command-line tool in a Cloud Shell session.
  • The following instructions outline how to start the session
  • Google Cloud Shell is free for customers of Google Cloud Platform which isn't free

Install GSUtil

Gsutil is a tool that enables you to access Google Cloud Storage from the command-line and is needed to configure Firebase Cloud Storage for CORS.
  • If you are behind a corporate proxy or firewall, the tool may not be able to access the internet with its default settings during installation. In this case you could use one of the self-contained versioned archives as detailed here.
  • Once you have successfully run gcloud init and been authenticated you can configure CORS
  • With the cors.json file created run the following command to deploy the configuration to your storage: 
    • bin/gsutil.cmd -d cors set  gs://

That should be all you need to do. 

No comments: