Support Forums

Next.js can not access public folder through netlify-function

Hi, I have a Next.js app in Netlify and in the api folder there is a file contact.js which it sends emails with nodemailer. But to send the email I have to look into the public folder to print an image in the mail body. When I am working locally with Next.js there isn’t any problem because to look to the image I have a variable with the root path and through it I can access the file, but when I make the deploy, the project structure is different and it fails when it looks for the path of the image. I was debugging it in the netlify functions section but it always print that the path doesn’t exist. Is there any solution to this?

Hi @diego-ceo,

The easiest way for you would to be encode the image in base64 and store it as a constant in the function.