Vercel Blob: "Invalid event type"
Unanswered
Ocicat posted this in #help-forum
OcicatOP
My client upload route returns "Vercel Blob: Invalid event type". Here's the request body:
and the handler:
{"type":"blob.generate-client-token","payload":{"pathname":"12789955_1001028386650453_1075820018_o_1001028386650453.jpg","callbackUrl":"https://wcut-git-development-schoodic-solutions.vercel.app/api/file/upload","clientPayload":"99a4ece0d290998f516a6c5b8be58397b340294503e1b23b4e820cd70ad7e8fc"}}and the handler:
import { handleUpload, type HandleUploadBody } from '@vercel/blob/client';
import type { NextApiResponse, NextApiRequest } from 'next';
export default async function handler(
request: NextApiRequest,
response: NextApiResponse,
) {
const body = request.body as HandleUploadBody;
console.log(request.body);
try {
const jsonResponse = await handleUpload({
body,
request,
onBeforeGenerateToken: async () => {
return {
allowedContentTypes: ['image/jpeg', 'image/png', 'image/gif'],
};
},
onUploadCompleted: () => new Promise<void>(resolve => resolve())
});
return response.status(200).json(jsonResponse);
} catch (error) {
console.log(error);
// The webhook will retry 5 times waiting for a 200
return response.status(400).json({ error: (error as Error).message });
}
}1 Reply
OcicatOP
I solved this. It wasn't immediately clear from the error that Blob returns, but I need to parse my body as JSON (which comes in as a string, but is typed as "any" on a NextApiRequest) before I pass it into handleUpload. Not a blob issue.