0

Problem

I have a server that needs to upload files, I have tried multiparty, connect-multiparty and multer. But every case, has the same problem: the file only uploads some times, i mean, i could send a file and there is a chance that the libraries don't parse the files, and never continue the code, resulting on not uploading the files.

In a While, the request send an error "Request Aborted", but its the normal response when the request time out

This is the problematic node.js file:

var multiparty = require('multiparty');
var multer = require('multer');
var upload = multer({
                    dest: "/uploads/"
                });

///----rest of code----

//1. Multiparty
app.post("/upload",[function(req, res){
     var form = new multiparty.Form({uploadDir:'/uploads/'});

    console.log("to upload")
    form.parse(req, function (err, fields, files) {
        console.log("uploaded");
        res.json({uploaded: true});
    })
}]


//2. multer

app.post("/upload2",[
    function(req, res, next){
        console.log("to upload");
        next();
    },
    upload.fields([
        {name: "file"},
        {name: "thumbnail"}
    ]),
    function(req, res){
        console.log("uploaded");
        res.json({uploaded: true});
    }]
Kaiden Prince
  • 472
  • 3
  • 18
  • Does a client have a time limit when waiting for response? Is it a unit test or manual file upload? Could it be a problem with network connection? – ezpn Oct 27 '15 at 22:09
  • the client have a limit for like one minute, after that the server respond with aborted, even if the file is small, and is not up to upload speed. – David Alejandro Londoño Mejía Oct 27 '15 at 22:24
  • and is not a unit test, is sending by android and by web, even using postman has the same error: the file upload some times and on others the libraries doesent resport error or data – David Alejandro Londoño Mejía Oct 27 '15 at 22:25
  • Are you sure that server returns a response as soon as it saves the file? Maybe you have some unhandled callback or you try to do asynchronous action synchronously? – ezpn Oct 27 '15 at 22:27
  • 1, the libraries dont save the file 2, i handle the callback of the libraries, and non of them return anything 3, i have it asynchronous and nor the callback of multiparty nor the multer middleware continue or return any data or error – David Alejandro Londoño Mejía Oct 27 '15 at 22:34
  • Please post the simplified version of your code for further debugging – ezpn Oct 27 '15 at 22:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93549/discussion-between-david-alejandro-londono-mejia-and-ezrepotein). – David Alejandro Londoño Mejía Oct 27 '15 at 23:19

2 Answers2

1

Make sure your form looks like this

<form enctype="multipart/form-data" action="..." method="..."> 
  ... 
</form>

And to be honest you will be better off using node-formidable. It is the most used multipart/form-data package on npm.

The example works straight out of the box.

Cheers

nodox
  • 333
  • 1
  • 5
  • 16
0

https://stackoverflow.com/a/23975955/4920678 I was using the setup from this answer, to use http and https over the same Port. Turns out, the setup with that proxy damaged the packages that where too large or something, and then the files never get parsed

Community
  • 1
  • 1