Increasing body limit size in apollo-server-express

若如初见. 提交于 2020-01-24 11:27:48

问题


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.

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 example snippet

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


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

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});

express example snippit

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

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.

Thanks

来源:https://stackoverflow.com/questions/55464415/increasing-body-limit-size-in-apollo-server-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!