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:
@@ -7,12 +7,17 @@ const STIRLING_PDF_API_KEY =
|
|||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
try {
|
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`, {
|
const res = await fetch(`${STIRLING_PDF_URL}/api/v1/misc/compress-pdf`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "X-API-KEY": STIRLING_PDF_API_KEY },
|
headers: {
|
||||||
body: formData,
|
"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) {
|
if (!res.ok) {
|
||||||
|
|||||||
@@ -7,14 +7,19 @@ const STIRLING_PDF_API_KEY =
|
|||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
try {
|
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(
|
const res = await fetch(
|
||||||
`${STIRLING_PDF_URL}/api/v1/security/remove-password`,
|
`${STIRLING_PDF_URL}/api/v1/security/remove-password`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "X-API-KEY": STIRLING_PDF_API_KEY },
|
headers: {
|
||||||
body: formData,
|
"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",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user