如何在 AWS Elastic Beanstalk 上的 Nodejs 应用程序上启用大文件的上传?
Posted
技术标签:
【中文标题】如何在 AWS Elastic Beanstalk 上的 Nodejs 应用程序上启用大文件的上传?【英文标题】:How can i enable the upload of large file on my Nodejs app on AWS Elastic Beanstalk? 【发布时间】:2020-08-17 18:29:27 【问题描述】:我有一个 Nodejs+Angular 应用程序,我将它部署在 AWS Elastic Beanstalk 上。在我的应用程序中,我有一个图像上传,并且 evrything 可以正常工作,除了大文件图像。我对此有一些配置:
在我的后端,我使用 multer 上传图片,并将文件限制设置为 10 MBmodule.exports = multer(storage: storage, limits: fileSize: 10 * 1024 * 1024 ).single('image');
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
一切都在我的本地机器上运行,但是当我部署应用程序时,当我尝试上传大于 1MB 的图像(multer 的默认大小限制)时,它给了我一个“CORS 错误”。
我是 AWS 配置的新手,所以我需要一些帮助。
【问题讨论】:
【参考方案1】:在“.elasticbeanstalk”目录下创建一个文件“proxy.config”
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
upstream nodejs
server 127.0.0.1:3020;
keepalive 256;
server
client_max_body_size 1G;
...
...
...
...
...
...
并像这样使用中间件:
const upload = multer(
limits: fileSize: 52428800
).single('image');
【讨论】:
以上是关于如何在 AWS Elastic Beanstalk 上的 Nodejs 应用程序上启用大文件的上传?的主要内容,如果未能解决你的问题,请参考以下文章