Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preservePath option not respected #1244

Open
cwkang1998 opened this issue Feb 23, 2024 · 2 comments
Open

preservePath option not respected #1244

cwkang1998 opened this issue Feb 23, 2024 · 2 comments
Labels

Comments

@cwkang1998
Copy link

cwkang1998 commented Feb 23, 2024

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:

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:

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?

@cwkang1998 cwkang1998 added the bug label Feb 23, 2024
@joeyguerra
Copy link

I believe 2.0.0-rc.4 adds code to pass this option to busboy. If you need something now, you can try that version with npm install multer@2.0.0-rc.4.

@cwkang1998
Copy link
Author

@joeyguerra Let me try it, if it works as expected then this shouldn't be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants