M
M
Maxim2017-09-18 14:01:11
gulp.js
Maxim, 2017-09-18 14:01:11

How to setup node.js environment for jquery.fileupload?

How should I set up the node.js environment for jquery.fileupload?
I'm working with gulp, I tried to install blueimp-file-upload-node, then run it with ./node_modules/blueimp-file-upload-node/server.js, but it didn't work. Nothing happens after launch.
Tried both with gallop on and off.
When uploading a file, it gives an error 404.

I took the information from here - https://github.com/blueimp/jQuery-File-Upload/wiki...

Plugin initialization:

$(function () {
    $("input[type=file]").fileupload({
      url: "http://localhost:3000",
      dataType: "json",
      done: function (e, data) {
        $.each(data.result.files, function (index, file) {
          $("<p/>").text(file.name).appendTo(document.body);
        });
      }
    });
  });

Codepen

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Gerasimov, 2017-09-18
@Omashu

the nodejs environment and this front-end plugin are not connected in any way, after selecting a file, the download starts automatically, and the request flies to the backend at the address / (root), 404 because it is not processed (caught)
in your backend, configure routes on the backend if express, something like this

app.post('/', (req, res, next) => {
  // ловим данные, загружаем файл (сохраняем на диск)
});

for the convenience of downloading the file, you can use this package https://github.com/felixge/node-formidable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question