L
L
logosan2015-06-29 05:44:05
Angular
logosan, 2015-06-29 05:44:05

How to submit form data along with files?

Hello. I ran into a problem that I can’t solve, maybe you can help) In general, you need to send data and a picture from the form, the picture is sent, but I can’t get data with input type = text.
client

<form class="add-mult-form" ng-submit="addMult(multName)">
    <div>
        <label for="multName">Название:</label>
        <input type="text" id="multName" ng-model="multName" required>
    </div>
    <div>
        <label for="multImg">Картинка:</label>
        <input type="file" id="multImg" nv-file-select uploader="uploader" required>
    </div>
    <div>
        <input type="submit" value="Добавить">
    </div>
</form>

$scope.uploader = new FileUploader({
    url: '/add_mult',
    method: 'POST'
});

$scope.addMult = function(multName) {
    $scope.uploader.formData.push({multName: multName});
    $scope.uploader.uploadAll();
};

server
app.post('/add_mult', [multer({ dest: '../src/client/image/mult/'}), function(req, res) {
    console.log(req.body.multName);
    res.end();
}]);

In the console I get Undefined

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Tartmin, 2015-06-29
@baskerville42

I use something like this - maybe it will simplify your task a little.

S
scapp, 2015-06-29
@scapp

Check if you have everything according to the documentation How to update FileItem options before uploading is done.

M
Mikhail Osher, 2015-06-29
@miraage

I tried all kinds of apploaders for AnguarJS - I found, in my opinion, the most thoughtful and convenient one.
https://github.com/danialfarid/ng-file-upload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question