How to enable Storage CORS with Node.js

207 views
Skip to first unread message

Vincent Bergeron

unread,
Aug 16, 2018, 10:55:53 AM8/16/18
to Firebase Google Group
Hi.

On this page:

It says this:
To programmatically set or get the CORS configuration for a bucket, use one of the client libraries for Cloud Storage. Use the following reference content to get started:

And there's a link to node.js bucket doc:

But I can't find any information on how to enable the CORS in this documentation.

Is there a doc or a tutorial that explains how to do this with the node.js Admin SDK?

Thanks

Vincent Bergeron

unread,
Aug 17, 2018, 3:34:27 PM8/17/18
to Firebase Google Group
For the record, you can set the cors by setting metadata on the bucket

const bucket = admin.storage().bucket();
const cors = [
        {
            origin: [
                '*'
            ],
            method: [
                '*'
            ],
            responseHeader: [
                'Content-Type', 'Cache-Control', 'Expires', 'Last-Modified', 'Content-Disposition'
            ],
            maxAgeSeconds: 3600
        }
    ];
    const metadata = { cors };

    return bucket.setMetadata(metadata);
Reply all
Reply to author
Forward
0 new messages