0

I have the following code, and when I upload a file, it just starts counting the % in the status bar and once reached 100% I get a 404 error on the file-upload path.

What might be the problem?

<form action="/file-upload", method="post", enctype="multipart/form-data">
  <input type="file", name="displayImage", id="file"></input>
  <input type="submit"></input>

app.post('/file-upload', function(req,res,next) {
  var fstream;
  req.pipe(req.busboy);
  req.busboy.on('file', function (fieldname, file, filename) {
    console.log("Uploading: " + filename);
    fstream = fs.createWriteStream(__dirname + '/files/' + filename);
    file.pipe(fstream);
  fstream.on('close', function () {
    res.redirect('back');
  });
});
konyv12
  • 716
  • 2
  • 8
  • 23

1 Answers1

0

The location that you're receiving the 404 status for is not your /file-upload location.

The fact that your upload seems to complete and then you receive the 404 indicates that your redirect at the end is redirecting to a route that is not valid.

res.redirect('back');

This probably doesn't do what you want.

Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138