With the introduction of Firebase Cloud Functions, we are looking at porting some of our current node.js server code to cloud functions. One of the problems I encountered is downloading a file from the GCS bucket to a temporary file on disk, and then sending it via email as an attachment (using mailgun-js).
A piece of code causing me grief:
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);
});
});
});
The error message I get in the function logs is:
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, . "" auth GCS, , . auth .config() GCS, Firebase? , ? GCS Firebase Storage node, .
,