I want to use multer on GAE, and I found multer-cloud-storage
library.
When using this library I have to set keyFilename
. keyFilename is explained as the path to the json key that you generated.
When to use it in dev environment, I set GOOGLE_APPLICATION_CREDENTIALS in env and set it to keyFilename. It's no problem. But when run on the GAE. GOOGLE_APPLICATION_CREDENTIALS is undefined so failed to build.
https://github.com/alexandre-steinberg/multer-cloud-storage
I think that the GOOGLE_APPLICATION_CREDENTIALS is auto generated on the GAE, but this understanding is maybe wrong.
CodePudding user response:
It seems your setup is only for local machine and not compatible for App Engine. The GOOGLE_APPLICATION_CREDENTIALS
environment variables is set automatically on Google App Engine and can access using Application Default Credentials.
It's also not recommended to store/use your service account file in your application. The recommended is using the Application Default Credentials (ADC) with Google Client libraries on App Engine. Here is the sample code using Multer on Google Cloud App Engine and it is well explained in John Hanley's answer with including tutorial link:
Google Client libraries support Application Default Credentials (ADC). This means that the libraries will attempt to find credentials for you automatically. The Client libraries can then use the environment to find the service account to use on Windows and automatically use the App Engine Default Service Account when deployed.
By including ADC in your code, you can test on Windows/Linux and deploy to App Engine without modifying your code and without the security risks of including a service account JSON file in your deployment.