增加 apollo-server-express 中的身体限制大小 [英] Increasing body limit size in apollo-server-express

查看:20
本文介绍了增加 apollo-server-express 中的身体限制大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 apollo-server-express 中的上传标量将文件上传到网络服务.我可以将小文件(10 多字节)上传到网络服务,但无法发送更大的文件.

I am trying to upload files to a webservice using the Upload scalar in apollo-server-express. I can upload small files(10s of kbs) to the webservice but am having trouble getting larger files to send.

我进行了一些搜索,发现可以使用 body-parser 包以及在中间件中设置的 bodyParserConfig 选项来更改主体大小限制.我已经尝试实现这一点,以及在 express 应用程序本身中实现它,但似乎都没有工作.

I did some searching and found that I can change the body size limit using the body-parser package, along with the bodyParserConfig option set in middleware. I've tried implementing this, as well as implementing it in the express app itself, however neither seem to be working.

bodyParserConfig 示例代码段

bodyParserConfig example snippet

const bodyParserConfig = bodyParser.urlencoded({limit: '50mb', extended: 'true', parameterLimit: 10000});


server.applyMiddleware({ app, path: process.env.GRAPHQL_ENDPOINT, bodyParserConfig});

我不确定是否需要在 apollo 服务内部使用 json 方法,它调用 json(config) 所以我尝试了这个,但它也没有用.

I'm not sure if I need to use the json method as inside the apollo service it calls json(config) so I tried this and it also didnt work.

const bodyParserConfig = {limit: '50mb'};


server.applyMiddleware({ app, path: process.env.GRAPHQL_ENDPOINT, bodyParserConfig});

表达示例代码段

app.use(bodyParser.json({limit: '50mb'}))

尝试这两个选项,以及来自 错误:请求的选项实体太大似乎不适合我.网络服务(Nifi HTTPHandleRequest)告诉我它无法接收内容.大多数解决方案示例(如上面的示例)专门针对 express 而不是 apollo-express-server,所以我不确定是否需要采用不同的方法.apollo-server 文档声明使用 bodyParserConfig 选项,所以我想知道我是否没有正确格式化配置.

Trying out both of these options, as well as options from Error: request entity too large don't seem to work for me. The webservice(Nifi HTTPHandleRequest) tells me it failed to receive content. Most examples of solutions(like the one above) have been specifically for express and not apollo-express-server so I'm not sure if theres a different approach I need to take. The apollo-server documents state to use the bodyParserConfig option, so I'm wondering if I'm not formatting the config correctly.

有什么简单的事情我做错了吗?另外我如何查看限制是多少?很难调试并查看我设置的选项是否真的在做任何事情.

Is there something simple I'm doing incorrectly? Also how can I view what the limit is? It's hard to debug and see if the options I'm setting are actually doing anything.

谢谢

推荐答案

我想调试的第一步是弄清楚发送或接收时是否发生故障.

I guess the first step in debugging is figuring out whether te faillure occurs on sending or receiving.

  1. 您能否将此消息发送到其他类型的网络服务?
  2. 您能否在 NiFi 中从其他工具接收此消息?

您没有提到消息有多大,但似乎在发送时您尝试将限制设置为 50MB.

You don't mention how large the messages are, but it seems that in sending you try to set the limit to 50MB.

我不认为这对 NiFi 来说一般来说是一个问题,但如果您专门使用 multipart/form-data,默认限制设置为 1MB.

I don't think this is a problem for NiFi in general, but if you are specifically using multipart/form-data the default limit is set to 1MB.

这可以通过设置进行调整:Multipart Request Max Size

This could be adjusted via the setting: Multipart Request Max Size

这篇关于增加 apollo-server-express 中的身体限制大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆