视觉产品搜索:client.createReferenceImage方法错误“错误:3 INVALID_ARGUMENT:无效的图像格式”

问题描述

我创建了一个云功能,可以从给定URL下载图像并将其上传到Firebase存储

async function downloadImageJimp(fileId,imageUrl) {
        const image = await jimp.read(imageUrl);
        await image.resize(900,900);
        return  image.writeAsync("/tmp/${fileId}.jpg");
   }
downloadImage(fileId,doc.data().imageUrl).then(val=>{
                            return bucket.upload(`/tmp/${fileId}.jpg`,{
                                destination: "my-destination-path",gzip: true,metadata: {
                                    metadata:{
                                        firebaseStorageDownloadTokens: uuidv4()
                                    }
                                }
                            }).then(val=>{
                                return bucket.file(`my-destination-path`).makePublic();
                            });

上传后,我编写的云函数触发了此功能

async function createImageReference(){
        try{
            const productPath = client.productPath(projectId,location,productId);
            const gcsUri=`gs://my-destination-path`;
            const referenceImageId=imageId;
    
            const referenceImage ={
                uri: gcsUri
            }
    
            const req = {
                parent: productPath,referenceImage: referenceImage,referenceImageId: referenceImageId
            }
            const [response] = await client.createReferenceImage(req);
            // console.log(`response.name: ${response.name}`);
            console.log(`response.uri: ${response.uri}`);
            return true;
        }catch(err){
            console.log(err);
            return false;
        }
    }

再次使用createImageReference()函数会返回错误消息“错误:3 INVALID_ARGUMENT:无效的图像格式”,即使下载的图像是jpg格式也是如此。我在做什么错了?

解决方法

关闭gzip。如果要降低GCS使用量,可以在导入后删除该图像。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...