3

I am trying to upload image using multer. The uploading part is okay but I also want to pass the object name/id to the index.js as I want to update the imageURL value in my product model.

Here is the html ::

<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="product in products">
            <td>{{$index + 1}}</td>
            <td>{{product.name}}</td>
            <td>
                <form action="/pictures/upload" method="POST"     
                      enctype="multipart/form-data"  
                      style="display:inline;">

                    <input type="hidden" name="pName" ng-value="product.name">
                    <input id="fileSelector" type="file" style="display:none;" name="avatar">
                    <input id="btnSubmit" type="submit" style="display:none;">

                </form>
            </td>
        </tr>
    </tbody>
</table>

This form is inside a table. But when I check the value of req.body.pName , it gives the value of the first product in the table regardless of the row from which the picture is being uploaded.

Here's the index.js :

router.post('/pictures/upload', function (req, res, next) {
  uploading(req, res, function(err){
    if (err) {
      console.log("Error Occured!");
      return;
    }
      console.log("Saved Successfully !!!");
      console.log(req.body.pName);
  });
   res.status(204).end();
});

What is it that I am doing wrong? any help would be appreciated.

Please advise if you think it might be done in any other way(not so complicated hopefully!).

Hadi J
  • 16,989
  • 4
  • 36
  • 62
nightElf91
  • 650
  • 1
  • 7
  • 28
  • sorry cant do that. Structure is very complicated. :( @Malai – nightElf91 Mar 02 '16 at 12:15
  • Is the value of the hidden input being updated? – ste2425 Mar 02 '16 at 12:24
  • no, I dont think so. It always shows the first row data. @ste2425 – nightElf91 Mar 02 '16 at 12:34
  • I believe this [SO](http://stackoverflow.com/questions/18446359/angularjs-does-not-send-hidden-field-value) question provides your answer then. I wasn't aware angular doesn't bind hidden inputs. Makes sense though from a performance point of view. No need to create another watch to update a field that isn't ever going to be seen. – ste2425 Mar 02 '16 at 12:36
  • yeah. But it says it works properly when using ng-value after angular 1.2. I also tried with/without brackets. @ste2425 – nightElf91 Mar 02 '16 at 12:48
  • I think it's not working because it's within a form. – nightElf91 Mar 02 '16 at 18:59

0 Answers0