は私がGithub provided by Firebase のサンプルコードからコードを次のですが、私は一貫して私のFirebase機能で Function returned undefined, expected Promise or value
は、エラー・ログを取得していますFirebase機能を書いています予想しました。Firebase:関数が未定義返され、約束または値
私は、私のコードをまったく同じように変更しましたが、猶予はありません。誰もこのコードを試しましたか?エラーフリーですか?エラーが発生するのはなぜですか?同じコードは、エラーを生成するサンプル・コードは
exports.imageToJPG = functions.storage.object().onChange(event => {
const object = event.data;
const filePath = object.name;
const baseFileName = path.basename(filePath, path.extname(filePath));
const fileDir = path.dirname(filePath);
const JPEGFilePath = path.normalize(path.format({dir: fileDir, name: baseFileName, ext: JPEG_EXTENSION}));
const tempLocalFile = path.join(os.tmpdir(), filePath);
const tempLocalDir = path.dirname(tempLocalFile);
const tempLocalJPEGFile = path.join(os.tmpdir(), JPEGFilePath);
// Exit if this is triggered on a file that is not an image.
if (!object.contentType.startsWith('image/')) {
console.log('This is not an image.');
return;
}
// Exit if the image is already a JPEG.
if (object.contentType.startsWith('image/jpeg')) {
console.log('Already a JPEG.');
return;
}
// Exit if this is a move or deletion event.
if (object.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return;
}
const bucket = gcs.bucket(object.bucket);
// Create the temp directory where the storage file will be downloaded.
return mkdirp(tempLocalDir).then(() => {
// Download file from bucket.
return bucket.file(filePath).download({destination: tempLocalFile});
}).then(() => {
console.log('The file has been downloaded to',
tempLocalFile);
// Convert the image to JPEG using ImageMagick.
return spawn('convert', [tempLocalFile, tempLocalJPEGFile]);
}).then(() => {
console.log('JPEG image created at', tempLocalJPEGFile);
// Uploading the JPEG image.
return bucket.upload(tempLocalJPEGFile, {destination: JPEGFilePath});
}).then(() => {
console.log('JPEG image uploaded to Storage at', JPEGFilePath);
// Once the image has been converted delete the local files to free up disk space.
fs.unlinkSync(tempLocalJPEGFile);
fs.unlinkSync(tempLocalFile);
});
});
任意のポインタの下にあるFirebase guide
でもありますか?
"デバッグのヘルプを求める質問(「なぜこのコードは動作しませんか?」)には、目的の動作、特定の問題またはエラー、および問題そのものを再現するために必要な最短コードが含まれている必要があります。他の読者にとって役に立ちません。参照してください:[最小限の、完全で検証可能な例(http://stackoverflow.com/help/mcve)]を作成する方法。 –
サンプルコードとドキュメントは、SDKの最近の変更を反映するように更新されていません。この質問を参照してください:https://stackoverflow.com/q/47128440/4815718、特にフランクのコメントがあります。 –
@BobSnyder - ありがとうございました。あなたのコメントは非常に役に立ちました。私はその質問に対する答えを見つけることができた。そして、あなたは叩かれました。ポインタを気に入る –