I'm trying to use a Blob, but when I fetch on my API, I get the error: SyntaxError: Unexpected token 'export' ??? My fetch function is (TSX file):
const handleUpload = async () => { const file = inputFileRef.current.files[0];
const response = await fetch(`/api/upload?filename=${file.name}`, { method: 'POST', body: file, }, );
const newBlob = (await response.json()) as PutBlobResult;
setBlob(newBlob); }And the API is (js file):
import { put } from '@vercel/blob';import { NextResponse } from 'next/server';
export async function POST(req) { const { searchParams } = new URL(req.url); const filename = searchParams.get('filename');
// Here's the code for Pages API Routes: const blob = await put(filename, req, { access: 'public', token: process.env.BLOB_READ_WRITE_TOKEN });
return NextResponse.json(blob);}
// The next lines are required for Pages API Routes onlyexport const config = { api: { bodyParser: false, },};
So the error is on export async function POST(req)
I don't know how to solve it ???
