node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7.01k stars 681 forks source link

How to avoid blank (empty) file create on the server #724

Closed xiongzhend closed 3 years ago

xiongzhend commented 3 years ago

For example, I have 3 file choose , and only pick the 1st file, and submit, then I got one real image uploaded and 2 blank files on the server, how to avoid that? Thanks.

GrosSacASac commented 3 years ago

options.allowEmptyFiles false

blueBlue0102 commented 3 years ago

@GrosSacASac if set options.allowEmptyFiles to false, will get exception: options.allowEmptyFiles is false, file size should be greather than 0 file uploading will fail

if set options.allowEmptyFiles to true, file uploading success but got the blank files

blueBlue0102 commented 3 years ago

with once submit POST file but will get two upload request

Example app listening at http://localhost:8080
parsing
files: application/octet-stream
parsing
files: image/jpeg
GrosSacASac commented 3 years ago

PR welcome

blueBlue0102 commented 3 years ago

After some Trial and error, I find out my frontend code has bug It will accidentally send two request with once submit POST in certain condition

After fixing bug, the exception and blank files are gone with options.allowEmptyFiles = false

Sorry for bothering!

tzwel commented 2 months ago

I am having the same problem, but I'm certain the POST request happens only once. When no files are uploaded I get the exception: options.allowEmptyFiles is false, file size should be greather than 0

tzwel commented 2 months ago

it also looks like formidable sees it as application/octet-stream so some data is actually being sent by my browser?