t3: accessing static files server side
I'm trying to use
fs.readFileSync to read PDFs and font files (.ttf) on the server (to dynamically build a PDF report in response to an API call), but I get ENOENT: no such file or directory no matter what I do. Even when the static file is in the same directory as the code trying to access it, I can't seem to target it. I noticed that __dirname targets /.next/server/app/api/trpc/[trpc] rather than the server-side file system, so I haven't been able to use it to help solve this problem. I feel like I must be missing something obvious, but I haven't found the answer yet.Solution
try using
reference: https://github.com/vercel/next.js/discussions/14341
in which dir have you stored those pdf and font files
i am assuming those files are stored inside your dir on build time as nextjs on vercel only allows temporary / ephemeral storage
process.cwd() instead of __dirnamereference: https://github.com/vercel/next.js/discussions/14341
in which dir have you stored those pdf and font files
i am assuming those files are stored inside your dir on build time as nextjs on vercel only allows temporary / ephemeral storage
GitHub
I'm trying to port some code to Next, and I'd say I was pretty familiar with how everything works, but this has stumped me (and there doesn't seem to be a mention in these discussions) ...
