gpt4 book ai didi

firebase - 将文件从 bucket1 复制到 Google Cloud Storage 中的 bucket2

转载 作者:行者123 更新时间:2023-12-05 02:15:41 26 4
gpt4 key购买 nike

我正在使用以下代码从我的云功能中的一个存储复制文件:

exports.copyFile = functions.storage.object().onFinalize((object) => {
const Storage = require('@google-cloud/storage');
const storage = new Storage();
const srcBucketName = 'bucket1';
const srcFilename = object.name;
const destBucketName = 'bucket2';
const destFilename = 'example.png';

storage
.bucket(srcBucketName)
.file(srcFilename)
.copy(storage.bucket(destBucketName).file(destFilename))
.then(() => {
console.log(
`gs://${srcBucketName}/${srcFilename} copied to gs://${destBucketName}/${destFilename}.`
);
return console.log('done!');
})
.catch(err => {
console.error('ERROR:', err);
})
});

我在日志中收到以下错误:

ERROR: { ApiError: Not Found
at Object.parseHttpRespBody....}

不确定缺少什么。有帮助吗?

最佳答案

const srcBucketName = 'bucket1';  
exports.copyFile = functions.storage.bucket(srcBucketName).object().onFinalize((object) => {
const Storage = require('@google-cloud/storage');
const storage = new Storage();
const srcFilename = object.name;
const destBucketName = 'bucket2';
const destFilename = 'file2';
storage
.bucket(srcBucketName)
.file(srcFilename)
.copy(storage.bucket(destBucketName).file(destFilename))
.then(() => {
console.log(
`gs://${srcBucketName}/${srcFilename} copied to gs://${destBucketName}/${destFilename}.`
);
return console.log('done!');
})
.catch(err => {
console.error('ERROR:', err);
})
});

关于firebase - 将文件从 bucket1 复制到 Google Cloud Storage 中的 bucket2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51511851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com