unable to process multi-part request on route handlers
Unanswered
Chestnut-backed Chickadee posted this in #help-forum
Chestnut-backed ChickadeeOP
import { headers } from "next/headers"
import { NextRequest, NextResponse } from "next/server"
import { simpleParser } from "mailparser"
import { createArticle } from "@/lib/database/article"
import { extractContentFromHtml } from "@/lib/server/epub"
export const config = { runtime: "experimental-edge" }
// Function to handle the background processing
// async function processRequest(to: string, from: string, file: File) {}
// header with simple auth
export async function POST(request: NextRequest) {
const auth = headers().get("Authorization")
console.log("auth", auth)
if (auth !== "ultra-secret-secure-token") {
return NextResponse.json({ message: "Unauthorized" }, { status: 401 })
}
console.log("Request received")
const formData = await request.formData()
const to = formData.get("to") as string
const from = formData.get("from") as string
const file = formData.get("file") as File
console.log("to", to)
console.log("from", from)
const fileContent = await file.text()
const parsed = await simpleParser(fileContent)
const htmlContent = parsed.html || parsed.textAsHtml
const article = extractContentFromHtml(htmlContent ?? "")
console.log("article", article)
await createArticle(article)
return NextResponse.json(
{
message: JSON.stringify({
status: "success",
message: "Request received and processing in the background",
}),
},
{ status: 200 }
)
}I have a simple route handler, it parses an email and parses the html out of it.
The code is not able to move past
const formData = await request.formData()this line. Any help is appreciated