fix: stream PDF body to Stirling to avoid FormData parse failure on large files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-11 13:48:05 +02:00
parent 0958238b25
commit ed504bd1de
2 changed files with 18 additions and 8 deletions
+9 -4
View File
@@ -7,12 +7,17 @@ const STIRLING_PDF_API_KEY =
export async function POST(req: NextRequest) {
try {
const formData = await req.formData();
// Stream body directly to Stirling — avoids FormData re-serialization
// failure on large files ("Failed to parse body as FormData")
const res = await fetch(`${STIRLING_PDF_URL}/api/v1/misc/compress-pdf`, {
method: "POST",
headers: { "X-API-KEY": STIRLING_PDF_API_KEY },
body: formData,
headers: {
"X-API-KEY": STIRLING_PDF_API_KEY,
"Content-Type": req.headers.get("content-type") || "",
},
body: req.body,
// @ts-expect-error duplex required for streaming request bodies in Node
duplex: "half",
});
if (!res.ok) {
+9 -4
View File
@@ -7,14 +7,19 @@ const STIRLING_PDF_API_KEY =
export async function POST(req: NextRequest) {
try {
const formData = await req.formData();
// Stream body directly to Stirling — avoids FormData re-serialization
// failure on large files ("Failed to parse body as FormData")
const res = await fetch(
`${STIRLING_PDF_URL}/api/v1/security/remove-password`,
{
method: "POST",
headers: { "X-API-KEY": STIRLING_PDF_API_KEY },
body: formData,
headers: {
"X-API-KEY": STIRLING_PDF_API_KEY,
"Content-Type": req.headers.get("content-type") || "",
},
body: req.body,
// @ts-expect-error duplex required for streaming request bodies in Node
duplex: "half",
},
);