Sunny Tambi
Sunny Tambi

Reputation: 2493

How can I read and write to Firebase Storage from within Cloud Functions for Firebase?

I want to save a file from Cloud Functions for Firebase to Firebase Storage.

I also want to read the file from Firebase Storage to Cloud Functions for Firebase at a later time.

I couldn't find any example for the same. Can someone help?

Upvotes: 8

Views: 7203

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

Cloud Functions run in a fairly standard V8 Node.js container. So you can use the regular Node SDK for Google Cloud Storage to interact with your files.

A snippet of code from the link:

// Upload a local file to a new file to be created in your bucket.
bucket.upload('/photos/zoo/zebra.jpg', function(err, file) {
  if (!err) {
    // "zebra.jpg" is now in your bucket.
  }
});

But really: just go to the link, it contains a better example than I'm willing to copy/paste here.

Upvotes: 10

Related Questions