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.04k stars 682 forks source link

Upload dir #853

Closed GrosSacASac closed 2 years ago

GrosSacASac commented 2 years ago

Allows to upload directories and keep their structure with on the client side

<input type="file" name="folder" webkitdirectory directory>

Add a new options createDirsFromUploads that will create necessary directories from filename before uploading process. For example if "a/b.txt" is sent in from the browser

then uploads folder will be uploads/a/b.txt

GrosSacASac commented 2 years ago

@Akxe and @wbt please review, if it looks good I will add a few automated test and then merge

GrosSacASac commented 2 years ago

Has to be used with filename option (otherwise hexoid creates a flat random name)

wbt commented 2 years ago

Well I feel a little silly for having recently spent a bunch of time implementing something similar outside Formidable. I haven't done any testing on the proposed code and see it's failing the existing automated tests, which seems concerning. I didn't spot any red flags in a quick pass through the code, but would likely want to see tests passing before I would recommend a merge.

GrosSacASac commented 2 years ago

Thanks for the input, some tests are failing but they failed before it has nothing to do with this change. There is an issue open about failing tests I think which I would try to handle after this PR.

Akxe commented 2 years ago

I am not sure about everything being sync fs operations.

From TS point of view, it does not change much...

Finally shouldn't there be some FS error handling? Does the form processing need to stop, because of an error in saving a file?

GrosSacASac commented 2 years ago

Closing in favor of https://github.com/node-formidable/formidable/pull/855 please have a look there