#1244·multer

`preservePath` option not respected

Author: cwkang1998Created Feb 23, 2024Updated Aug 27, 2026
Labelsbug

Currently, when passing preservePath as an option to multer, it seems that its not respected and the path were not preserved.

The input provided is in the format Buffer, passed like so in the test file using supertest:

typescript
const reqInstance = testApp.post(
 /upload-multiple
);

// Add files
codeFiles.forEach((file) => {
  reqInstance.attach(
    `files`,
    file.data, // buffer,
    {filename:  `/some/path/${file.name}.txt` }
  );
});

const response = await reqInstance
  .set("Content-Type", "multipart/form-data")
  .expect(200)

The server is setup like so:

typescript

const app = express();
const upload = multer({ storage: memoryStorage(), preservePath: true });

app.post("/upload-multiple", upload.array("files"), (res) => {
   console.log(res.files[0].originalname) // here it shows only {file.name}.txt, not the full path.
   return "OK"
})

Have not tried to replicate this using busboy yet, will do so if I manage to find time for the replication.

Is this behaviour expected?