node.js - Can we limit upload file size without uploading it fully? -


i'm using multer v1.3.0 express v4.15.4.

i have used filesize limits below

multer({     storage: storage,     limits: {filesize: 1*1000*50, files:1},     filefilter: function (req, file, cb) {         if (_.indexof(['image/jpeg', 'image/png'], file.mimetype) == -1)             cb(null, false);         else             cb(null, true)     } }); 
  • in case dont think limits working. cause not getting limit_file_size error.

  • if remove filefilter i'm getting limit_file_size error.

  • but in both cases first whole file getting uploaded & filesize checked.

its not @ upload 1gb of file , check of 1mb or not. want know if there has way stop uploading in middle when file size limit exceeds. don't want rely on content-length.

from looking through multer , busboy source looks calculates data size running total , stops reading stream filesize reached. see code here:

https://github.com/mscdex/busboy/blob/8f6752507491c0c9b01198fca626a9fe6f578092/lib/types/multipart.js#l216

so while 1gb might uploaded shouldn't saved anywhere.

if want stop upload continuing think you'd have close socket though haven't experimented myself. i'm not aware of way respond cleanly while request still trying upload data.

related:

yes or no: can server send http response, while still uploading file correlative http request?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -