Node.js + restify cant upload file

2019-07-07 06:04发布

问题:

Im having problems uploading files to a node.js application using restify.

This is my upload code https://gist.github.com/maumercado/7ab5cbbfd27c6b825044

Apparently the events are not being triggered, but I dont really know the reason, also the files are being created, but once I see the size info it says 0 bytes.

also this is the server.js file https://gist.github.com/maumercado/ecf948b4b8fc7d39e69e

Im using a post request in order to upload the file and node 0.10.7.

What can be wrong with the code??

Thank you

回答1:

It looks like restify.bodyParser() works the same as express.bodyParser(), in that it will handle the upload for you (and in the process consume the body data passed with the request, so there's nothing left to read once your handler is called – hence, no events either).

The uploaded data is written to a temporary file, req.files.selfie.path in your case.

As for what you're intending to do (upload progress), I don't think it's possible, unless you implement the functionality of bodyParser() itself. But I'm not overly familiar with the inner workings of Restify to be 100% sure about that.

If you're working with a browser as a client, you could implement upload progress there instead.