R
R
retr02017-11-29 10:58:28
JavaScript
retr0, 2017-11-29 10:58:28

Uploading files in Node.js?

It is necessary to implement the following process:
From the Android application using Java, send a file/image to the Node.js server. The server processes the file and stores it in its directory.
By what means is it possible to implement a server with similar functionality and is it possible at all? That is: it is necessary that the server somehow gets the file from the client's request.
I know that in Node.js file uploads can be implemented using forms, but this does not suit me. I will be grateful for help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Decadal, 2017-11-29
@retr0

FileManager.uploadFileToS3(req.file('file'), function(err, uploadedFiles) {
            if (err) {
                //...
            }

here is the code directly from sails, uploaded to amazon s3, android and ios app worked with it.
Of course, uploading files is real, the node is able to handle such things.
When sending a file, the client (mobile application) needs to specify the correct headers. At a minimum, the correct content type, content-type : multipart/form-data

V
Vahe, 2017-11-29
@vahe_2000

use node-formidable

server.post("/uploads", (req, res) => {
  new formidable.IncomingForm()
    .parse(req)
    .on("file", function(name, file) {
      console.log("Got file:", name);
    })
    .on("field", function(name, field) {
      console.log("Got a field:", name);
    })
    .on("error", function(err) {
      next(err);
    })
    .on("end", function() {
      res.end();
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question