OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Getting "[object Object]" when uploading the .pdf file from browser through multer

  • Thread starter Thread starter ViNtr0
  • Start date Start date
V

ViNtr0

Guest
basically the title that i am getting nothing from the browser and also postman, I cannot even see print the console.log statements because it just stuck on object Object.

Code:
const multer = require("multer");
const path = require("path");

// Multer configuration
const storage = multer.diskStorage({
  destination: path.join(__dirname, "../public/uploads/"), // Destination folder for uploads
  filename: (req, file, cb) => {
    cb(
      null,
      file.fieldname + "-" + Date.now() + path.extname(file.originalname)
    );
  },
});

// Multer instance for single file upload
const upload = multer({
  storage: storage,
  limits: { fileSize: 5000000 }, // 5MB file size limit
}).single("filePath"); // 'filePath' should match the name attribute in your HTML form input

module.exports = upload;

my html file name tag is the same as "single("filePath");

I have tried doing changes that i first included multer config in directly app.js file then in the controller which was using it then a separate file and i got the same result. This below is my folder structure (https://i.sstatic.net/FyrcWSLV.png) (https://i.sstatic.net/51E4VALH.png)

<p>basically the title that i am getting nothing from the browser and also postman, I cannot even see print the console.log statements because it just stuck on object Object.</p>
<pre><code>const multer = require("multer");
const path = require("path");

// Multer configuration
const storage = multer.diskStorage({
destination: path.join(__dirname, "../public/uploads/"), // Destination folder for uploads
filename: (req, file, cb) => {
cb(
null,
file.fieldname + "-" + Date.now() + path.extname(file.originalname)
);
},
});

// Multer instance for single file upload
const upload = multer({
storage: storage,
limits: { fileSize: 5000000 }, // 5MB file size limit
}).single("filePath"); // 'filePath' should match the name attribute in your HTML form input

module.exports = upload;
</code></pre>
<p>my html file name tag is the same as "single("filePath");</p>
<p>I have tried doing changes that i first included multer config in directly app.js file then in the controller which was using it then a separate file and i got the same result.
This below is my folder structure
(<a href="https://i.sstatic.net/FyrcWSLV.png" rel="nofollow noreferrer">https://i.sstatic.net/FyrcWSLV.png</a>)
(<a href="https://i.sstatic.net/51E4VALH.png" rel="nofollow noreferrer">https://i.sstatic.net/51E4VALH.png</a>)</p>
 

Latest posts

P
Replies
0
Views
1
Paras Chouhan
P
Top