Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ export async function POST(request: Request): Promise<NextResponse> {
},
});

const blob = await vercelBlob.put(pathname, emptyStream, {
access: 'public',
multipart: true,
addRandomSuffix: true,
});
try {
const blob = await vercelBlob.put(pathname, emptyStream, {
access: 'public',
multipart: true,
addRandomSuffix: true,
});

return NextResponse.json(blob);
return NextResponse.json(blob);
} catch (error) {
// The server rejects empty multipart uploads ("Invalid body") which is
// expected. The important thing is that put() resolved instead of hanging.
return NextResponse.json(
{ resolved: true, error: (error as Error).message },
{ status: 400 },
);
}
}
7 changes: 4 additions & 3 deletions test/next/test/@vercel/blob/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ test.describe('@vercel/blob', () => {
timeout: 15000, // Should resolve fast, not deadlock
},
);
// The upload resolves (no deadlock). The server may reject the empty
// multipart upload, but the important thing is it doesn't hang.
expect(res.status()).toBeLessThan(500);
// The server rejects the empty multipart upload (400) which is fine.
// The important thing is it resolved instead of hanging (15s timeout).
const data = (await res.json()) as { resolved: boolean };
expect(data.resolved).toBe(true);
});
});

Expand Down
Loading