我的目标是实现Firebase的缩放图像扩展,上传一张图片,然后当调整大小完成后,将该下载URL的缩略图添加到Cloud Firestore文档中。这个问题对我有所帮助,但仍然无法识别缩略图并获取下载URL,这是我一直在尝试的。
注意:我将我的缩略图设置为根目录/缩略图。
const functions = require('firebase-functions');
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
exports.thumbsUrl = functions.storage.object().onFinalize(async object => {
const fileBucket = object.bucket;
const filePath = object.name;
const contentType = object.contentType;
if (fileBucket && filePath && contentType) {
console.log('Complete data');
if (!contentType.startsWith('thumbs/')) {
console.log('This is not a thumbnails');
return true;
}
console.log('This is a thumbnails');
} else {
console.log('Incomplete data');
return null;
}
});