【问题标题】:Fix Hapi version 19.0.3 error 415 unsupported media type upload file with multipart/form-data修复 Hapi 版本 19.0.3 错误 415 不支持的媒体类型上传文件与 multipart/form-data
【发布时间】:2020-06-12 14:08:23
【问题描述】:

我搜索并找不到正确的答案。 我似乎很无奈。但幸运的是,visua 代码帮助调试了代码,我在 index.js@hapi/subtext/lib 文件中找到了这一行

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


         return await internals.multipart (req, options, source, contentType);
     }

然后我在路由器选项中修复了 multipart = true:

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

它奏效了。感谢您的 visua 代码调试。我回信给可能会收到此错误的人。知道如何处理。

我使用 hapi 版本 19.0.3

【问题讨论】:

  • 同样的问题。你解决了吗?

标签: hapijs


【解决方案1】:

形成 hapi 19 发行说明:

将路由 options.payload.multipart 默认更改为 false 路由配置默认更改为禁用多部分处理。您需要为整个服务器启用它以保持以前的行为,或者只为需要多部分处理的路由启用它。

server.route({
    method: 'POST',
    path: '/submit',

    options : {
        auth : false,
        payload: {
          output: 'stream',
          parse: true,
          allow: 'multipart/form-data',
          multipart : true  // <== this is important in hapi 19
        },
        handler: async (req, h) => {
            console.log(req);
        }
    }
});

【讨论】:

    猜你喜欢
    • 2017-08-28
    • 2016-08-21
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2018-07-25
    • 2016-09-09
    相关资源
    最近更新 更多