gpt4 book ai didi

node.js - 错误 : request entity too large in graphql services of node

转载 作者:搜寻专家 更新时间:2023-11-01 00:16:58 25 4
gpt4 key购买 nike

我正在研究基于 Node 的 graphql 项目,试图将 base64 格式的图像发送到服务器。

我正在使用 bodyparser 模块并将其配置为如下所示。

app.use(bodyparser.text({type: 'application/graphql'}));

app.use(bodyparser.json({limit: '50mb'}));
app.use(bodyparser.urlencoded({limit: '50mb', extended: true}));

我可以通过直接 Node 服务发送 base64 图像,但是当涉及到 graphql 服务时,它会抛出错误:

Error: request entity too large

最佳答案

为了帮助其他使用 graphql-yoga npm 包的人。添加 bodyparser 选项的语法完全不同,我花了几个小时调试并试图让它工作,所以在此处添加代码以供引用:

const { GraphQLServer } = require("graphql-yoga");

const server = new GraphQLServer({
schema, //Your schema
context, //Your context
});

const options = {
port: 1234
bodyParserOptions: { limit: "10mb", type: "application/json" },
};

server.start(options, () =>
console.log(
"Server is running\m/"
)
);

关于node.js - 错误 : request entity too large in graphql services of node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41486401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com