How do I read the contents of a new cloud storage file of type .json from within a cloud function?

后端 未结 2 684
误落风尘
误落风尘 2021-02-06 05:38

The event passed to my Google cloud function only really tells me the name of the bucket and file, and whether the file was deleted. Yes, there\'s more there, but i

2条回答
  •  别跟我提以往
    2021-02-06 06:38

    npm install @google-cloud/storage --production
    

    package.json:

    {
      "main": "app.js",
      "dependencies": {
        "@google-cloud/storage": "^1.2.1"
      }
    }
    

    You should achieve that npm ls shows no errors like npm ERR! missing:.

    app.js:

    ...
    
      const storage = require("@google-cloud/storage")();
      storage.
        bucket("mybucket").
        file("myfile.txt").
        download( function(err, contents) {
          console.log(contents.toString());
        } );
    

提交回复
热议问题