0

I need to get a simple file upload solution for a new website. I am trying to Filepond for upload and a small program to save the file to the local file-system.

I have gone through the following code on a fresh Ubuntu LTS 18 machine.

https://codeunshackled.com/2018/11/03/React-File-Uploader-With-Node-Express/

Filepond provides no error details, giving the message "Error during upload". I have tried using the onerror event but console.log doesn't seem to get triggered. The server and the frontend are both on the same Linux box on different ports.

There is an alternate server method using the so called PHP Boilterplate via vagrant. There the vm does not boot and it looks too cumbersome for a small file upload solution.

I have successfully used the following Nodejs code to upload the file and save it. However, if I try to point Filepond to this server, it just gives the same ambiguous message, "Error during upload".

var http = require('http');
var formidable = require('formidable');
var fs = require('fs');

http.createServer(function (req, res) {
  if (req.url == '/fileupload') {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
      var oldpath = files.filetoupload.path;
      var newpath = 'C:/Users/Your Name/' + files.filetoupload.name;
      fs.rename(oldpath, newpath, function (err) {
        if (err) throw err;
        res.write('File uploaded and moved!');
        res.end();
      });
 });
  } else {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
    res.write('<input type="file" name="filetoupload"><br>');
    res.write('<input type="submit">');
    res.write('</form>');
    return res.end();
  }
}).listen(8080);
Adeel Hashmi
  • 767
  • 1
  • 8
  • 20
  • 1
    The "error during upload" is an error intended for the user, not the developer. I think opening your developer tools network tab you should be able to see the outgoing request and the actual server response. That should give you more information into what is going on. – Rik Feb 20 '19 at 07:42

1 Answers1

0

Thanks for the help, @Rik. Using the Chrome debug tools, I could see that the port number was wrong. Although I had given filepond the right port number, it was still trying to connect to server on its default port 3000.

Adeel Hashmi
  • 767
  • 1
  • 8
  • 20