Vision product search: client.createReferenceImage method error "Error: 3 INVALID_ARGUMENT: Invalid image format"
Vision product search: client.createReferenceImage method error "Error: 3 INVALID_ARGUMENT: Invalid image format"
我创建了一个云函数,可以从给定的 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() 函数避免 returns 错误消息“错误:3 INVALID_ARGUMENT:图像格式无效”,即使下载的图像是 jpg 格式。我做错了什么?
关闭 gzip。如果您想降低 GCS 使用率,可以在导入后删除图像。
我创建了一个云函数,可以从给定的 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() 函数避免 returns 错误消息“错误:3 INVALID_ARGUMENT:图像格式无效”,即使下载的图像是 jpg 格式。我做错了什么?
关闭 gzip。如果您想降低 GCS 使用率,可以在导入后删除图像。