0

I write API in order to client upload file. API has content-type multiple/form-data. But I don't know get values from client send to my

router.post('/upload/file', async (req, res) => {
var body = "";
try {
    req.on('data', function (chunk) {
        body += chunk;
    });
    req.on('end', function () {
        console.log('body: ' + body);
        var formData = new FormData(body);
        console.log("=====================", formData.entries);
        // var {accessTok, type, file} = req.params;
        //
        // if (!accessTok || !type || !file) {
        res.json({
            code: -1000,
            message: 'Missing parameter(s). Please provide accessToken, type upload, file upload.'
        });
        res.end();
        return null;
    })
    // }
}catch(err){
    res.json({err: err.message});
    res.end();
    return;
}

I tried use FormData but not done. I get error is not function, formData.getKey('') is them same.

TraiTran
  • 63
  • 1
  • 6
  • Editing some code to your question might clarify your problem. It is quite unclear currently. – pirho Nov 22 '17 at 09:02
  • `var formData = new FormData(body); console.log("=====================", formData.entries);` I use get values from formData but not working – TraiTran Nov 22 '17 at 09:24

0 Answers0