How to load static image in server/api in Nuxt3?

85 Views Asked by At

I am trying to implement an API function in the built-in server in Nuxt (Nitro). Right now in this function I am generating a PDF using JSPdf but I can't insert images into the PDF when I deploy it to production (in Vercel). Right now when I run the app with npm run dev it works.

My code is the following:

  let filepath2 = path.join(process.cwd(), "assets", "images", "logo2.png");

  const data = fs
    .readFileSync(
      filepath2
    )
    .toString(encoding);

  const uri = "data:" + mime + ";" + encoding + "," + data;

  doc.addImage(uri, "png", x, y, logoWidth, logoHeight, "logo", "MEDIUM", 0);

This works in local with npm run dev, but when I deploy it to Vercel it shows an error telling it can't find the file.

How can I access a image in server side when I deploy it?

0

There are 0 best solutions below