Read files from filesystem when deployed to vercel #7394
-
Hi Guys ;), I have a small api endpoint which reads files from the public folder and just sends them back. The problem is when deployed to vercel the folder structure changes and I always get invalid path... I have deployed already ten different versions with different solutions to find out the path. export async function GET() {
const imagePath = path.join(import.meta.url, 'static', 'image.jpg')
const asset = await fs.readFile(imagePath);
return new Response(asset, {
headers: {
"Content-Type": "image/jpg"
}
})
} I tried
const imagePath = path.resolve(process.cwd(), 'image.jpg') Thank you for your help ;). Have a nice day 😉 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Did you ever fix this issue? |
Beta Was this translation helpful? Give feedback.
-
Update for all: use the new Watch an explanation from Rich here https://www.youtube.com/watch?v=m4G-6dyF1MU |
Beta Was this translation helpful? Give feedback.
Update for all: use the new
read
API that simplifies reading files from the filesystem / deployment environment.Watch an explanation from Rich here https://www.youtube.com/watch?v=m4G-6dyF1MU