How to upload Bulk file in rails 3 application

If you want to upload bulk file in rails application just follow the following steps

1) create a rails application
    rails new bulk_upload

2) Add passenger in your gem file
    gem 'passenger'

Now try to start with your rails application with the command
  passenger start

by default it will run on port number 3000

Now if you try to upload bulk files lets just say more than 500 mb or 800 mb you will get an error in the time of uploading like

[error] 4840#0: *557 client intended to send too large body: 94672000 bytes, client: 127.0.0.1, server: _, request: "POST /XXX HTTP/1.1", host: "localhost:3000"

so this not error of you application this is the error thrown by passenger and ngnix which is responsible to run passenger


First uninstall using purge to remove even configuration files and records:
 apt-get purge nginx nginx-common nginx-full

Then reinstall it
 apt-get install nginx

If above doesn't work for you you can also try using --force-confmiss option of dpkg.
 sudo dpkg --force-confmiss -i /var/cache/apt/archives/nginx-common_*.deb

Now after successful installation of the ngnix we need to configure nginx to support bulk file upload.

First go to the ngnix config page using the command

 sudo nano /etc/nginx/nginx.conf

 Modify the line in the http Block to change the client_max_body_size according to your requirement

  http {
    .....
    client_max_body_size 200M;
    ....
  }

Remember that if browser intend to send data larger than client_max_body_size then again you will get the same error as ngnix can not accept the data large than the client_max_body_size.

Now restart ngnix now it works fine ... but for uploading you need to set the server response time according to your requirement.

You can also change the response time of the web server to avoid time out error.

Comments

Post a Comment

Popular posts from this blog

Debug Nodejs inside docker container

Swap primary keys between two records in the same table in Postgres

How to add a bootstrap table with fixed header and scrollable body