uploadthing in vercel serverless function

Can some help out with out to do this in vercel? It works locally, but File isn't going to work in a serverless function although I did try. I'm trying to debug something and my last attempt before I tear my hair out is to upload some screenshots from puppeteer so I can see why the page state is different in this particular scenario. I just need the data format to work in a serverless function and none of my AI friends have been able to help me out.
await page.goto(targetUrl)
const screenshot = await page.screenshot({
type: 'png',
fullPage: true,
})
const file = new File([screenshot], `screenshot-${Date.now()}.png`, {
type: 'image/png',
})
const uploadResult = await utapi.uploadFiles([file])
await page.goto(targetUrl)
const screenshot = await page.screenshot({
type: 'png',
fullPage: true,
})
const file = new File([screenshot], `screenshot-${Date.now()}.png`, {
type: 'image/png',
})
const uploadResult = await utapi.uploadFiles([file])
Error on vercel
error Error: File is not defined
error Error: File is not defined
2 Replies
agentsmith
agentsmithOP2mo ago
update vercel functions to node 20
Looks like that fixed it. Totally obvious, but id didn't think about the node environment vercel was using.

Did you find this page helpful?