本文介绍了修复了Hapi版本19.0.3错误415不支持具有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
推荐答案
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的媒体类型上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!