Han*_*aez 7 javascript firebase google-cloud-functions firebase-storage
这是我要实现的目标,实现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)
小智 -1
您需要使用 filePath 来检查拇指
if(filePath.startswith('thumbs/'){...}
contentType 具有文件的元数据,例如图像类型等。FilePath 将具有完整路径。
| 归档时间: |
|
| 查看次数: |
157 次 |
| 最近记录: |