0

I apologize if this question seems really familiar. I have multiple places where I am using forms to send data to server. Here is the html.

 <form action="/dashboard/inventory/" method="post" enctype="multipart/form-data">
     <input type="date" class="form-control" id="receivingdate" placeholder="Select Receiving Date" required />
     <input type="file" class="custom-file-input" id="workorderfile" required />
     <button type="submit" class="btn btn-primary">
         Submit
     </button>
 </form>

In my app.js I have

app.use(fileUpload());
app.use(bodyParser.urlencoded({
    extended: true}));
app.use(bodyParser.json());

Yet When I try to access the date with req.body I get an empty object and null for req.files I have used this process on multiple places yet this is the only form that is giving me a headache. Any Suggestions?

2 Answers 2

1

here is simple code

<form  action="/upload" method="POST" enctype="multipart/form-data">

  <label>write name</label>
  <input type="file" name="file" value="">
  <br></br>
  <label>Upload image</label>
  <input type="file" name="photo"  />
  <br></br>
  <input type="submit" value="submit">
</form>

router file

router.post('/upload',  (req, res, next) => {
  const file = req.files.file;
  const img = req.files.photo;

in my main app.js file

const bodyParser= require('body-parser');
 const fileUpload = require('express-fileupload');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(fileUpload());
Sign up to request clarification or add additional context in comments.

1 Comment

I just realized that I forgot to attach a name attribute. I am so sorry. THANKS.
1

Attach a name attribute to input tags.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.