#fileList

1 messages · Page 1 of 1 (latest)

hazy crystal
#

my form send fileList and in client before send toapi i got the data are in object 0: FileList {name: aishdahs.jpg }

but when in my api the data be an object but empty data in it fileList {}

covert elmBOT
#

Hi @hazy crystal. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, it seems like you're trying to handle file uploads in Next.js API routes. In Next.js 13 and later, you can access form data directly from the request object using request.formData(). This returns a promise that resolves with a FormData object.

Here's an example of how you can handle file uploads:

export async function POST(request: Request) {
  const formData = await request.formData();
  const file = formData.get('file');
  // rest of your code
}

In this example, file is a File object that represents the uploaded file. You can access various properties of the file such as name, type, and size.

If you're still having issues, it might be due to the way you're sending the file from the client. Make sure you're sending the file as part of a FormData object and that the server is correctly configured to handle file uploads.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: