0

I am using the express-fileupload module to upload pdf files and store into mysql database. I can only upload pdf files < 10mb. I want to allow a bigger bandwidth of files to be uploaded e.g 50mb.

Here is my router:

app.use(fileUpload({ limits: { fileSize: 50 * 1024 * 1024 } })); // needed for file upload
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({
    limit: '50mb',
    extended: true
}));

I can see my file is 100% uploaded on the chrome browser upload bar however my app crashes soon after that with this error:

events.js:183 throw er; // Unhandled 'error' event

Error: Can't write in closed state

I have tried increasing the connection timeout for mysql, i.e to 600000, however still facing the same issue.

1 Answers1

0

Looks like I fixed it. It was because the maximum packet transfer for mysql connection was by default 4MB. You can change it to a size of your own:

SET GLOBAL max_allowed_packet=1073741824;

Or change it on the my.ini file: How to change max_allowed_packet size

  • 1
    You know you are setting this value globally to ~1.07Gb?... i would set max_allowed_packet as a session varariable from the application it self something like `connection.query("SET SESSION max_allowed_packet = 100000000");` (100000000 bytes = 100Mb) right after you connect to the database. – Raymond Nijland Apr 07 '18 at 23:27
  • Yes, I know. I just added that as an example. – Sadman Sakib Hasan Apr 08 '18 at 00:59
  • Expect OOM if you have substantial number of concurrent users when using 1G max_allowed_packet. Setting Session limit would be in your best interest. – Wilson Hauck Apr 12 '18 at 20:21