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
7k stars 680 forks source link

Added the option to only keep the last part of the original filename as the extension if the keepExtensions option is set to true #888

Closed Wengiel31 closed 1 year ago

Wengiel31 commented 1 year ago

Added option "longExtentions" (defaults to false). If this is set and "keepExtensions" is set to true extension of the new filename will be random.c instead of random.b.c assuming that the original filename was a.b.c. This fixes issue 887.

Also removed an additional space on line 524 of Formidable.js

GrosSacASac commented 1 year ago

I am not sure. This kind of PR has the potential to go infinite. If everyone starts adding a boolean option to half change something in the output this lib can grow in a monstrosity

GrosSacASac commented 1 year ago

Consider using the options.filename . this will let you do what you want with the name and extension

Wengiel31 commented 1 year ago

Consider using the options.filename . this will let you do what you want with the name and extension

In order to do that I would need access to original filename to which I only get the access it in the callback of form.prase, but I need that original filename to create that form with the .parse method

GrosSacASac commented 1 year ago

No. You also access to originalFilename in the filename function

                filename: (name, ext, part/*, form*/) => {
                    const {originalFilename} = part;