简体   繁体   English

如何将Node.js中的文件上传到服务器?

[英]How do I upload file in nodejs to a server?

I have bean searching the Internet on how to upload a file to a web server from nodejs. 我有bean在Internet上搜索如何从nodejs将文件上传到Web服务器。 I found some stuff but it told you how to upload to a nodejs server and not some other web server. 我发现了一些东西,但是它告诉您如何上传到nodejs服务器而不是其他Web服务器。 So my qutions is how can I upload a file using nodejs to a web serve? 所以我的问题是如何使用nodejs将文件上传到Web服务?

Use the http module and pipe a file stream to the request. 使用http模块并将文件流通过管道传递到请求。

var req = http.request(options, function(res) {
});

req.on('error', function(err) {
  throw err;
});

fs.createReadStream(file).pipe(req);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM