随着Firebase云端功能的推出,我们正在考虑将我们当前的一些node.js服务器端代码移至云端功能。我遇到的一个问题是将文件从GCS存储区下载到磁盘上的临时文件,然后通过电子邮件将其作为附件(使用mailgun-js)发送。firebase云功能Google云端存储API错误
的一段代码导致我的悲伤是:
return mkdirp(tempLocalDir).then(() => {
const bucket = gcs.bucket(gcsBucket);
const tempFilePath = tempLocalDir + gcsFile;
return bucket.file(gcsFile).download({
destination: tempFilePath
}).then(() => {
console.log('File downloaded locally to', tempFilePath);
var messageSubject = "Test";
var messageBody = "Test with attach";
var mailgunData = {
from: ,
to: agentEmail,
subject: messageSubject,
html: messageBody,
attachment: tempFilePath,
};
mailgunAgent.messages().send(mailgunData, function (error, body) {
console.log(body);
});
});
});
我得到的功能日志中的错误信息是:
ApiError: Forbidden
at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:156:33)
at Object.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:131:18)
at Duplexify.<anonymous> (/user_code/node_modules/@google-cloud/storage/src/file.js:724:21)
at emitOne (events.js:96:13)
at Duplexify.emit (events.js:188:7)
at emitOne (events.js:96:13)
at DestroyableTransform.emit (events.js:188:7)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1108:14)
我已经能够将文件下载到在磁盘上的/ tmp /文件夹使用请求,这将是后备选项,但我真的想尽可能使用GCS工具。我“认为”这是一个GCS认证错误,但我不知道如何跟踪。对于GCS,我需要在云功能的.config()中使用不同的身份验证参数吗?如果是这样,我怎么输入它们?我们的GCS存储桶和项目在Firebase存储的引入之前发布,但我们已成功将它用于运行在我们服务器上的节点功能。
由于提前, 扎克
感谢您的回复。不幸的是,我已经尝试过了,但它不起作用。我想我可能有一个认证问题,但是在追踪时遇到问题。 – Zach