Node.js 使用google中等图像触发器时应用程序/八位字节流问题(模糊图像)

Node.js 使用google中等图像触发器时应用程序/八位字节流问题(模糊图像),node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,一、 我使用谷歌的中等图像解决方案。 我从一家公司得到了这个解决方案 我请一些人为我升级此解决方案&以下是代码: “严格使用” const gm=require('gm')。子类({imageMagick:true}) const functions=require('firebase-functions') const admin=require('firebase-admin') admin.initializeApp() const Vision=require(“@google clo

一、 我使用谷歌的中等图像解决方案。 我从一家公司得到了这个解决方案 我请一些人为我升级此解决方案&以下是代码:

“严格使用”
const gm=require('gm')。子类({imageMagick:true})
const functions=require('firebase-functions')
const admin=require('firebase-admin')
admin.initializeApp()
const Vision=require(“@google cloud/Vision”)
const vision=new vision.ImageAnnotatorClient()
const spawn=require('child-process-promise')。spawn
const path=require('路径')
常量fs=require('fs')
const{Storage}=require(“@googlecloud/Storage”)
const gcs=新存储({
项目编号:XXXXXXXXXX,
})
exports.blurOffensiveImages=functions.storage
.object()
.onFinalize(异步(对象)=>{
const file=gcs.bucket(object.bucket).file(object.name)
const filePath=`gs://${object.bucket}/${object.name}`
log(`analysising${file.name}.`)
试一试{
const[result]=等待视野。安全搜索检测(文件路径)
const detections=result.safeSearchAnnotation | |{}
如果(
detections.成人===“非常可能”||
detections.暴力===“非常可能”
) {
log(`检测到${file.name}不合适。`)
等待模糊图像(文件,object.bucket,object.metadata)
console.log('Deleted local file',file)
返回空
}否则{
log(`检测到${file.name}正常。`)
}
}捕捉(错误){
console.error(`分析${file.name}失败。`,错误)
失误
}
})
异步函数blurImage(文件、bucketName、元数据){
const templacalPath=`/tmp/${path.parse(file.name.base}`
const bucket=gcs.bucket(bucketName)
等待文件。下载({目的地:tempLocalPath})
log('文件已下载到',tempLocalPath)
//使用ImageMagick模糊图像。
等待新的承诺((决定,拒绝)=>{
总经理(tempLocalPath)
.blur(0,20)
.write(templacalPath,(err,stdout)=>{
如果(错误){
console.error('模糊图像失败',err);
拒绝(错误);
}否则{
log(`muzzle image:${file.name}`);
解决(标准输出);
}
});
});
log('在创建模糊图像',tempLocalPath)
等待bucket.upload(tempLocalPath{
目标:file.name,
元数据:{元数据:元数据},
})
console.log('模糊图像上载到存储在',文件)
返回fs.unlink(templeCalPath,(e)=>{if(e){console.log(e)}})

}
您能详细说明一下您的触发器卡住的原因吗?是否有调试输出或错误消息?完全没有((控制台清除)完全没有错误(这是一个很好的触发器,但可能只针对一个图像,&a我根本不知道什么是resason&如何修复多个图像上载的问题如果您要上载多个图像,我在此处找到了一个链接()。我认为您可以使用此处的代码。