小编Han*_*aez的帖子

firebase的大小调整扩展完成后获取“下载网址”

这是我要实现的目标,实现Firebase的调整大小图像扩展名,上传图像,然后在调整大小完成后,将dowloadUrl的拇指添加到Cloud Firestore文档中。这个问题对我有帮助,但仍然无法识别出拇指并获得下载URL,这是到目前为止我们一直在尝试的方法。

注意:我将缩略图设置为root / thumbs

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;
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-functions firebase-storage

7
推荐指数
1
解决办法
157
查看次数