I wrote an express server using node.js and TypeScript.
The server can receive an array of images and send them further on to an external API.
When running locally it works perfectly well, but after deployment to Render hosting service I get this error from the Catch part of the "Try and Catch":
Apr 24 05:57:33 PM Something went wrong, ReferenceError: FormData is not defined
Does anybody have an idea why is that?
this is the code:
import { AbstractDao } from "./AbstractDao";
export class PlanetNetDao extends AbstractDao{
readonly basicURL: string
#API_KEY: string
constructor(){
super()
this.basicURL = 'https://my-api.plantnet.org'
this.#API_KEY = process.env.PLANET_NET_API_KEY
}
async fetchIdentifyPlantPost(originalImageNames: string[]) {
try {
const formData = new FormData()
for (let i = 0 ; i < originalImageNames.length ; i++) {
const imageFile = this.fsReadFileSync(originalImageNames[i])
const blob = new Blob([imageFile], { type: 'image/jpeg' })
formData.append('images', blob)
this.removeImageFromStorage(originalImageNames[i])
}
const response = await fetch (`${this.basicURL}/v2/identify/all?include-related-images=true&no-reject=false&lang=en&api-key=${this.#API_KEY}`,
{method: 'POST',
body: formData})
const res = await response.json()
return res
} catch (err) {
console.log('Something went wrong, ' + err)
throw err
}
}
}```