修复了Hapi版本19.0.3错误415不支持具有multipart/form-data的媒体类型上传文件 [英] Fix Hapi version 19.0.3 error 415 unsupported media type upload file with multipart/form-data
问题描述
我进行了搜索,但找不到正确的答案. 我似乎很无奈.但是幸运的是,visua代码帮助调试了代码,我在index.js@hapi/subtext/lib文件中找到了这一行
I searched and couldn't find the right answer. I seem helpless. But luckily the visua code helped debug the code and I found this line in the index.js@hapi/subtext/lib file
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:
I then fixed multipart = true in router opitions:
{
payload: {
maxBytes: 1024 * 1024 * 100,
// timeout: false, // important
parse: true,
output: 'data',
allow: 'multipart / form-data',
multipart: true
}
}
,它奏效了.感谢您的visua代码调试.我写信给可能会收到此错误的人.知道如何处理.
and it worked. Thanks for the visua code debug. I wrote back to someone who might get this error. Know how to handle.
我使用的是hapi版本19.0.3
i using hapi version 19.0.3
推荐答案
表格hapi 19发行说明:
默认情况下将路线options.payload.multipart更改为false 路由配置默认更改为禁用多部分处理.您将需要为整个服务器启用它以保持以前的行为,或者仅针对需要多部分处理的路由启用它.
Form hapi 19 release notes :
Change route options.payload.multipart to false by default Route configuration default was change to disable multipart processing. You will need to either enable it for the entire server to keep previous behavior or just for the routes where multipart processing is required.
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);
}
}
});
这篇关于修复了Hapi版本19.0.3错误415不支持具有multipart/form-data的媒体类型上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!