I created a cloud function that downloads an image from a giving url and uploads it to firebase storage
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();
});
after the upload, a cloud function i wrote triggers this function
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;
}
}
The createImageReference() function avove returns an error message "Error: 3 INVALID_ARGUMENT: Invalid image format" even thought the downloaded image is in jpg format. what am i doing wrong?
Turn off gzip. If you want to keep down GCS usage, you could delete the image after import.