issues deleting an image using Cloud Functions for Firebase and @google-cloud/storage

后端 未结 2 797
广开言路
广开言路 2021-02-14 07:56

I\'m trying to create a script in Cloud Functions for Firebase that will react to a db event and remove an image that has its path in one of the params (\"fullPath\").

t

相关标签:
2条回答
  • 2021-02-14 08:42

    ok, so i got this solved. here are my conclusions:

    • you need to add to your buckets name the ".appspot.com". Its not written anywhere in the docs and getting your bucket name in firebase is hard enough for someone that is not familiar in the google cloud. I hope they will add this little peace of information into their docs or make it clear what is your bucket's name in firebase.
    • use the environment variable process.env.GCLOUD_PROJECT, it should have your project id that is identical to your bucket id in firebase. again, remember to add the .appspot.com suffix to it.
    • regarding the credentials to GCS, you don't need to provide them when using cloud functions for firebase. you seem to be authenticated already.
    0 讨论(0)
  • 2021-02-14 08:47

    Make sure your bucket name doesn't include gs://

    Eg. instead of gs://my-project-id.appspot.com use my-project-id.appspot.com

    let bucket = gcs.bucket('my-project-id.appspot.com')

    This may happen to you (as it did to me) if you copy your bucket name from, for instance, Android code, where you can use full URL to connect with storage, ie. storage.getReferenceFromUrl('gs://my-proj...

    .

    Also, it seems the projectId variable you use to initialise gcs doesn't need the appspot.com suffix (but it shouldn't break if you have it included). Ie. projectId:'my-project-id' should be suffice.

    Lastly, the GCS node package docs states you need to generate separate JSON to pass as keyFilename to test things locally. Good news is - you can use the Firebase Admin SDK key, as described in the Get Started Server/Admin docs instead.

    0 讨论(0)
提交回复
热议问题