expressjs / expressjs/multer

`preservePath` option not respected

Open
#1,244 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
12.1k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
21

Description

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.