You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hapi 19.0.3上传文件报415不支持媒体类型问题排查与解决

Fixing 415 Unsupported Media Type When Uploading multipart/form-data in Hapi 19.0.3

I recently ran into a frustrating 415 Unsupported Media Type error while trying to upload files using multipart/form-data with Hapi 19.0.3. After searching around without finding a working solution, I turned to debugging in VS Code to get to the bottom of it.

I traced the issue to the @hapi/subtext/lib/index.js file, where I found this key code snippet:

if (contentType.mime === 'multipart/form-data') { 
  if (options.multipart === false) {// Defaults to true 
    throw Boom.unsupportedMediaType(); 
  } 
  return await internals.multipart(req, options, source, contentType); 
}

It turned out the error was being thrown because even though multipart defaults to true, my route's payload configuration must have been overriding this behavior implicitly.

The fix was straightforward: explicitly set multipart: true in the route's payload options. Here's the full configuration that resolved the issue for me:

{ 
  payload: { 
    maxBytes: 1024 * 1024 * 100, 
    parse: true, 
    output: 'data', 
    allow: 'multipart/form-data', 
    multipart: true 
  } 
}

Once I added that explicit multipart: true line to the payload settings, the 415 error vanished and file uploads started working as expected.

I'm sharing this solution in case other developers hit the same roadblock—sometimes explicitly defining a default value is all it takes to resolve these tricky media type issues in Hapi.

内容的提问来源于stack exchange,提问作者Tran Hoang Hiep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 19:13:11