R.D*_*ans 9 google-cloud-platform google-cloud-functions
我在浏览器上使用GCP控制台.我创建了一个函数如下:
function listFiles(bucketName) {
// [START storage_list_files]
// Imports the Google Cloud client library
const Storage = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
storage
.bucket(bucketName)
.getFiles()
.then(results => {
const files = results[0];
console.log('Files:');
files.forEach(file => {
console.log(file.name);
});
})
.catch(err => {
console.error('ERROR:', err);
});
// [END storage_list_files]
}
exports.helloWorld = function helloWorld (req, res) {
if (req.body.message === undefined) {
// This is an error case, as "message" is required
res.status(400).send('No message defined!');
}
else {
// Everything is ok
console.log(req.body.lat);
console.log(req.body.lon);
listFiles("drive-test-demo");
res.status(200).end();
}
}
Run Code Online (Sandbox Code Playgroud)
字面上我现在想要做的就是列出存储桶中的文件,如果某个HTTPS触发器通过的话.
我的package.json文件如下:
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"@google-cloud/storage": "1.5.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误"无法找到模块'@ google-cloud/storage'"
到目前为止我看到的大多数查询已经通过使用npm install解决了,但考虑到我的index.js和package.json文件存储在gcloud存储桶内的zip文件中,我不知道该怎么做.关于如何解决这个问题的任何建议都会得到很好的解释.
Ser*_*rge 13
打开控制台,将dir更改为函数项目并输入:
npm install --save @google-cloud/storage
Run Code Online (Sandbox Code Playgroud)
就这样!
| 归档时间: |
|
| 查看次数: |
5435 次 |
| 最近记录: |