【发布时间】:2021-05-10 01:36:56
【问题描述】:
我正在尝试使用 Node.js 库创建一个 GCP 存储桶。 我一直在使用这里的步骤: https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-nodejs
下面粘贴的代码。 挑战在于我的存储桶一直在错误的项目中创建。我的项目在我的 gcloud cli 中设置,在我的节点环境中设置,在我的脚本中设置。 有没有办法在传递给库的 createBucket 函数的值中设置项目?
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const storageClass = 'Name of a storage class, e.g. coldline';
// const location = 'Name of a location, e.g. ASIA';
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
async function createBucketWithStorageClassAndLocation() {
// For default values see: https://cloud.google.com/storage/docs/locations and
// https://cloud.google.com/storage/docs/storage-classes
const [bucket] = await storage.createBucket(bucketName, {
location,
[storageClass]: true,
});
console.log(
`${bucket.name} created with ${storageClass} class in ${location}.`
);
}
createBucketWithStorageClassAndLocation();
【问题讨论】:
标签: node.js google-cloud-platform google-cloud-storage gcloud