Skip to content

Specific file names cause the extension to not be set correctly with options.keepExtensions "test(.123).pdf" #980

@spudcud

Description

@spudcud

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): community
  • Currently blocking your project/work? (yes/no):
  • Affecting a production system? (yes/no): yes

Context

  • Node.js version: 18.18.0
  • Release Line of Formidable (Legacy, Current, Next): Current
  • Formidable exact version: 3.5.1
  • Environment (node, browser, native, OS): node
  • Used with (popular names of modules):

What are you trying to achieve or the steps to reproduce?

I am setting the option keepExtensions: true but when the file contains a period in the name with other characters it screws up the filePath created. It takes the first instance of the period and uses it instead of the final period. What is odd is I looked at using options.filename to get this corrected (which works) but the ext passed into the function is correctly '.pdf'.

import formidable from 'formidable';

const getFile = (req) => {
  return new Promise((resolve, reject) => {
    const form = formidable({
      keepExtensions: true,
    });

    form.parse(req, (err, fields, files) => {
      if (err) {
        return reject(err);
      }

      const { file: fileArr } = files;
      const file = fileArr[0];

      return resolve({
        path: file.filepath,
        fileName: file.originalFilename,
        uploadType: fields?.uploadType?.[0],
        docType: fields?.docType?.[0],
      });
    });
  });
};

export default getFile;

What was the result you got?

These are files we received from clients that caused issues processing:
'test(.123).pdf' - became '8316b5c96ab192694f1fd3a00.123'
'EERS 1.1-CUR.pdf' - became '8316b5c96ab192694f1fd3a01.1'

image

What result did you expect?

The filepath was expected to have the correct extension .pdf

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions