Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploading raw data to a firebase storage bucket in a Google Cloud function?

I have a Google Cloud Function and I'm trying to save some data into Firebase storage. I'm using the firebase-admin package to interact with Firebase.

I'm reading through the documentation (https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-nodejs) and it seems to have clear instructions on how to upload files if the file is on your local computer.

// Uploads a local file to the bucket
await storage.bucket(bucketName).upload(filename, {
  // Support for HTTP requests made with `Accept-Encoding: gzip`
  gzip: true,
  metadata: {
    // Enable long-lived HTTP caching headers
    // Use only if the contents of the file will never change
    // (If the contents will change, use cacheControl: 'no-cache')
    cacheControl: 'public, max-age=31536000',
  },
});

In my case through, I have a Google Cloud Function which will be fed some data in the postbody and I want to save that data over to the Firebase bucket.

How do I do this? The upload method only seems to specify a filepath and doesn't have a data parameter.

like image 210
Diskdrive Avatar asked Mar 05 '23 15:03

Diskdrive


1 Answers

Use the save method:

storage
  .bucket('gs://myapp.appspot.com')
  .file('dest/path/in/bucket')
  .save('This will get stored in my storage bucket.', {
    gzip: true,
    contentType: 'text/plain'
  })
like image 71
Raine Revere Avatar answered Mar 08 '23 23:03

Raine Revere