Node.js + restify cant upload file

六眼飞鱼酱① 提交于 2019-12-23 20:15:50

问题


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.



来源:https://stackoverflow.com/questions/16683989/node-js-restify-cant-upload-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!