0

I want to see content of the file that is posted from the client i am using fs module so with below code contents is coming undefined , Any idea what is missing in below code ?

I have file printed in server side to make sure i am gettign the data.

server.js

var data = new multiparty.Form();
var fs = require('fs');

export function create(req, res) {
    data.parse(req, function(err,files) {
        var file = files.file;
        console.log(file);
        fs.readFile(file, 'utf8', function(err, contents) {
            console.log('content',contents);
        });
    });
};
5
  • 1
    Did you check the err? Are you sure it's UTF8? Commented Oct 31, 2016 at 18:35
  • the file contains xml Commented Oct 31, 2016 at 18:37
  • 1
    @hussain — that doesn't answer either of Kwakwak's questions. Commented Oct 31, 2016 at 18:40
  • i checked err i do not see any server side. Commented Oct 31, 2016 at 18:52
  • and yes it is utf-8 Commented Oct 31, 2016 at 18:52

1 Answer 1

1

I guess the problem might be the signature of the callback you are supplying to data.parse (you are missing the fields argument).
Check it yourself by looking to the examples on multiparty docs

var data = new multiparty.Form();
var fs = require('fs');

export function create(req, res) {
    data.parse(req, function(err, fields, files) {
        var file = files.file;
        console.log(file);
        fs.readFile(file, 'utf8', function(err, contents) {
            console.log('content',contents);
        });
    });
};
Sign up to request clarification or add additional context in comments.

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.