我正在使用AWS Lambda中的Google Cloud Storage和我的笔记本电脑本地第一次玩。我使用Lambda设置环境变量
GOOGLE_APPLICATION_CREDENTIALS
但是,当我尝试在zip中上传demo.txt文件时,我得到了
'bucketName' has already been declared
我在Google Cloud中创建了存储桶,并启用了API。任何人都可以帮助修复代码吗? (主要取自谷歌云文档)
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]
}
你和bucketName
有冲突:
uploadFile
的论据:
async function uploadFile(bucketName, filename) {
uploadFile
当地宣布它:
const bucketName = 'mynewbucket-saturday';
您只需选择一种指定存储桶名称的方法,然后删除另一种方法。