N
Nuxt2mo ago
Dustin

Transfer-Encoding: chunked in Nuxt/Nitro

Hi! I'm trying to create a webhook endpoint in Nuxt that receives binary data (video files) from security cameras. The cameras send data with Transfer-Encoding: chunked and Content-Type: video/x-matroska. I'm getting [cause]: invalid transfer-encoding header errors when trying to use Nuxt's server routes. Here's what I've tried:
// server/api/webhook.post.ts
export default defineEventHandler(async (event) => {
try {
const body = await readBody(event); // Fails here
// ... process body
} catch (error) {
console.error("Error:", error); // invalid transfer-encoding header
}
});
// server/api/webhook.post.ts
export default defineEventHandler(async (event) => {
try {
const body = await readBody(event); // Fails here
// ... process body
} catch (error) {
console.error("Error:", error); // invalid transfer-encoding header
}
});
I've also tried: - readRawBody(event) - same error - Creating middleware to handle chunked encoding - Using different content-type headers - The same webhook works perfectly with Express.js, but I'd prefer to keep everything in Nuxt if possible. Questions: - Is there a way to handle chunked encoding in Nuxt server routes? - Should I use a different approach for binary data? - Are there any Nuxt-specific solutions for this use case? Environment: - Nuxt 4.1.3 - Node.js 18+ - Security cameras sending binary data with chunked encoding Thanks for any guidance!
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @Dustin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but based on the provided knowledge sources, there is no explicit documentation or example for handling incoming requests with Transfer-Encoding: chunked and binary data (such as video files) in Nuxt server routes or Nitro. Here’s what is clear from the sources: - Nuxt server routes (using Nitro/h3) provide helpers like readBody(event) and readRawBody(event) for reading request bodies, but your error (invalid transfer-encoding header) suggests that Nitro/h3 may not support chunked transfer encoding for incoming requests out of the box. The documentation does not mention support for this use case, nor does it provide a workaround for binary streaming uploads from clients using chunked encoding Nuxt 4 server directory. - The only mention of streaming in the docs is for sending streams to the client (e.g., with sendStream), not for receiving them Advanced Usage: Sending Streams. - There is no mention of low-level request handling or custom parsing of chunked uploads in the Nuxt/Nitro documentation. To answer your questions: - Is there a way to handle chunked encoding in Nuxt server routes?
The knowledge sources do not provide a way to handle incoming requests with Transfer-Encoding: chunked. The error you are seeing suggests this is not currently supported by Nitro/h3. - Should I use a different approach for binary data?
The documentation does not describe an alternative approach for handling binary uploads with chunked encoding. If you control the client, you might try sending the data as a standard POST with a known Content-Length, but this may not be possible with your cameras. - Are there any Nuxt-specific solutions for this use case?
There are no Nuxt-specific solutions documented for handling chunked binary uploads from clients. The only streaming support described is for sending data to clients, not receiving it. Summary:
Nuxt/Nitro’s current server route system does not appear to support handling incoming requests with Transfer-Encoding: chunked for binary data uploads. If this is a critical requirement, you may need to use a custom server (like Express) for this endpoint, or consider submitting a feature request or issue to the Nitro repository. If you find new documentation or updates in the future, it may be worth revisiting this, but as of now, the knowledge sources do not contain a solution for your use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@239748199818985472> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?