Next.js Discord

Discord Forum

Am I returning CSV file correctly from API route?

Unanswered
Capple posted this in #help-forum
Open in Discord
Avatar
Hello,

I'm wondering if I'm returning the CSV file from my API route correctly.

export const GET = auth(async function GET(req) {

 const headers = new Headers();
    headers.append("Content-Type", "text/csv");
    headers.append("Content-Disposition", `attachment; filename="products_${format(new Date(), "yyyy-MM-dd")}.csv"`);

    const csvStream = stringify(rows, { header: true, delimiter: ";", bom: true });

    return new NextResponse(csvStream as any, { headers });

}


This works and I can download the file but If I remove the any I get a typescript error
Argument of type 'Stringifier' is not assignable to parameter of type 'BodyInit | null | undefined'.
Type 'Stringifier' is missing the following properties from type 'URLSearchParams': size, append, delete, get, and 8 more.ts(2345)

0 Replies