简体   繁体   English

如何使用NodeJS,Nginx和base64上传图像? (413 PayloadTooLargeError:请求实体太大)

[英]How to upload an image using NodeJS, Nginx and base64? (413 PayloadTooLargeError: request entity too large)

I am trying to upload 5 base64 images using Postman raw text option, with application/json header set. 我正在尝试使用Postman原始文本选项上传5张base64图像,并设置了application / json标头。 The server keeps returning the error mentioned. 服务器不断返回所提到的错误。 I am using NodeJS behind Nginx reverse proxy. 我在Nginx反向代理后面使用NodeJS。

I have tried all of the options mentioned in the code below, including increasing the limits up to (100M), which apparently wasn't the issue. 我尝试了以下代码中提到的所有选项,包括将限制增加到(100M),这显然不是问题。

NodeJS (MAXIMUM_FILE_SIZE_LIMIT='500mb'): NodeJS(MAXIMUM_FILE_SIZE_LIMIT ='500mb'):

app.use(bodyParser.urlencoded({ limit: process.env.MAXIMUM_FILE_SIZE_LIMIT, parameterLimit: 100000, extended: true }));
app.use(bodyParser.json({ limit: process.env.MAXIMUM_FILE_SIZE_LIMIT, extended: true }));
// app.use(bodyParser.text({ limit: process.env.MAXIMUM_FILE_SIZE_LIMIT, extended:true }));
app.use( bodyParser.text({type : 'application/text-enriched', limit: process.env.MAXIMUM_FILE_SIZE_LIMIT}) );   
app.use( bodyParser.raw({limit: process.env.MAXIMUM_FILE_SIZE_LIMIT}) );   

Nginx Nginx的
Configuration inside (server, http, location): 内部配置(服务器,http,位置):
nginx.conf, nginx.conf,
sites-enabled/default, 网站启用/默认,
sites-available/default: 网站可用/默认:

client_max_body_size 100M

I want to succeed uploading the images (5), which their total size is not more than 2MB. 我想成功上传图像(5),其总大小不超过2MB。

The solution finally was to leave the nginx's client_max_body_size 5M; 最终的解决方案是将Nginx的client_max_body_size 5M;保留为client_max_body_size 5M; only at the nginx.conf , as-well as using the following lines in my NodeJS code: 仅在nginx.conf ,以及在NodeJS代码中使用以下几行:

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

PLEASE NOTE!!! 请注意!!!
After trying a lot of combinations the problem appeared to be unrelated to the metnioned above, at all. 尝试了多种组合后,该问题似乎与上面提到的问题无关。
While using the node command in-order to execute the server, everything worked great. 在按顺序使用node命令执行服务器时,一切工作正常。 But, because I wanted to keep the application alive (in-case of a server reboot), I have used forever . 但是,因为我想保持应用程序正常工作(套内的服务器重启),我用forever
Forever started the application, but apparently kept throwing the 413 error everytime, regardless of nginx's and node's settings. Forever启动了该应用程序,但显然每次都始终抛出413错误,无论nginx和节点的设置如何。
Switched to PM2 , which finally solved that. 切换到PM2 ,最终解决了该问题。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PayloadTooLargeError:上传图片时请求实体太大 - PayloadTooLargeError: request entity too large when upload image PayloadTooLargeError:使用angular 7和nodejs express上传图像时请求实体太大 - PayloadTooLargeError: request entity too large in uploading image using angular 7 and nodejs express PayloadTooLargeError:请求实体太大 - PayloadTooLargeError: request entity too large 413 请求实体太大 nginx/1.14.0 - 413 Request Entity Too Large nginx/1.14.0 出现错误:我在均值js中发送base64图像时,请求实体太大错误 - getting Error: request entity too large error when i send base64 image in mean js PayloadTooLargeError: 请求实体太大。 在 NestJS 中如何解决? - PayloadTooLargeError: request entity too large. How solve it in NestJS? Gatsby 函数:PayloadTooLargeError:请求实体太大 - Gatsby Functions: PayloadTooLargeError: request entity too large Express: PayloadTooLargeError: 请求实体太大 - Express: PayloadTooLargeError: request entity too large Nodejs 负载在 base64string 上太大(Http 413) - Nodejs Payload too large(Http 413) on base64string 413 实体太大,弹性豆茎上的 nginx nodejs - 413 entity too large, nginx nodejs on elastic beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM