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

后端 未结 2 814
广开言路
广开言路 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: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.

提交回复
热议问题