【发布时间】:2019-03-09 15:08:09
【问题描述】:
我第一次在 AWS Lambda 中使用Google Cloud Storage,也在我的笔记本电脑上进行了本地操作。我使用
在 Lambda 中设置了环境变量GOOGLE_APPLICATION_CREDENTIALS
但是,当我尝试在 zip 中上传 demo.txt 文件时,我得到了
'bucketName' has already been declared
我在 Google Cloud 中创建了存储桶并启用了 API。任何人都可以帮助修复代码吗? (反正大部分取自 Google Cloud 文档)
async function uploadFile(bucketName, filename) {
// [START storage_upload_file]
// Imports the Google Cloud client library
const { Storage } = require('@google-cloud/storage');
// Your Google Cloud Platform project ID
const projectId = 'apple-ration-27434';
// Creates a client
const storage = new Storage();
var bucketName = 'mybucket-saturday';
var filename = 'demo.txt';
// Uploads a local file to the bucket
await storage.bucket(bucketName).upload(filename, {
// Support for HTTP requests made with `Accept-Encoding: gzip`
gzip: true,
metadata: {
// Enable long-lived HTTP caching headers
// Use only if the contents of the file will never change
// (If the contents will change, use cacheControl: 'no-cache')
cacheControl: 'public, max-age=31536000',
},
});
console.log(`${filename} uploaded to ${bucketName}.`);
// [END storage_upload_file]
}
【问题讨论】:
标签: javascript node.js google-cloud-platform aws-lambda google-cloud-storage