【问题标题】:How can i enable the upload of large file on my Nodejs app on AWS Elastic Beanstalk?如何在 AWS Elastic Beanstalk 上的 Nodejs 应用程序上启用大文件的上传?
【发布时间】:2020-08-17 18:29:27
【问题描述】:

我有一个 Nodejs+Angular 应用程序,我将它部署在 AWS Elastic Beanstalk 上。在我的应用程序中,我有一个图像上传,并且 evrything 可以正常工作,除了大文件图像。我对此有一些配置:

  • 在我的后端,我使用 multer 上传图片,并将文件限制设置为 10 MB

module.exports = multer({storage: storage, limits: { fileSize: 10 * 1024 * 1024 }}).single('image');

  • 我还有一个名为“01_files.config”的配置文件,我使用此代码部署应用程序

files: "/etc/nginx/conf.d/proxy.conf" : mode: "000755" owner: root group: root content: | client_max_body_size 20M;

一切都在我的本地机器上运行,但是当我部署应用程序时,当我尝试上传大于 1MB 的图像(multer 的默认大小限制)时,它给了我一个“CORS 错误”。

我是 AWS 配置的新手,所以我需要一些帮助。

【问题讨论】:

    标签: node.js amazon-web-services file-upload amazon-elastic-beanstalk large-files


    【解决方案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');
    

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2012-07-05
      • 2018-09-14
      • 2012-06-26
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2013-11-19
      相关资源
      最近更新 更多