Google Storage is not a constructor error

前端 未结 1 1703
眼角桃花
眼角桃花 2021-01-11 19:06

I am building an App and my objective is every time someone upload an image to firebase storage, the cloud function resize that image.

...
import * as Storag         


        
相关标签:
1条回答
  • 2021-01-11 19:45

    The API documentation for Cloud Storage suggests that you should use require to load the module:

    const Storage = require('@google-cloud/storage');
    

    This applied to versions of Cloud Storage prior to version 2.x.

    In 2.x, there was a breaking API change. You need to do this now:

    const { Storage } = require('@google-cloud/storage');
    

    If you would like TypeScript bindings, consider using Cloud Storage via the Firebase Admin SDK. The Admin SDK simply wraps the Cloud Storage module, and also exports type bindings to go along with it. It's easy to use:

    import * as admin from 'firebase-admin'
    admin.initializeApp()
    admin.storage().bucket(...)
    

    admin.storage() gives you a reference to the Storage object that you're trying to work with.

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