When trying to access an image in my home directory of Firebase storage with node.js functions, I'm getting [object Object] as a response. I guess I initialized the bucket incorrectly, but not sure where I'm going wrong.
That's the debug info in firebase functions:
ChildProcessError: `composite -compose Dst_Out [object Object] [object Object] /tmp/output_final2.png` failed with code 1
Here's my code:
const admin = require('firebase-admin');
admin.initializeApp();
const storage = admin.storage();
const os = require('os');
const path = require('path');
const spawn = require('child-process-promise').spawn;
exports.onFileChange= functions.storage.object().onFinalize(async object => {
const bucket = storage.bucket('myID.appspot.com/');
const contentType = object.contentType;
const filePath = object.name;
console.log('File change detected, function execution started');
if (object.resourceState === 'not_exists') {
console.log('We deleted a file, exit...');
return;
}
if (path.basename(filePath).startsWith('changed-')) {
console.log('We already changed that file!');
return;
}
const destBucket = bucket;
const tmpFilePath = path.join(os.tmpdir(), path.basename(filePath));
const border = bucket.file("border.png");
const mask1 = bucket.file("mask1.png");
const metadata = { contentType: contentType };
return destBucket.file(filePath).download({
destination: tmpFilePath
}).then(() => {
return spawn('composite', ['-compose', 'Dst_Out', mask1, border, tmpFilePath]);
}).then(() => {
return destBucket.upload(tmpFilePath, {
destination: 'changed-' + path.basename(filePath),
metadata: metadata
})
}); });```
const bucket = storage.bucket('myID.appspot.com/');are you declaring your default bucket?border.pngfile?