相关疑难解决方法(0)

将上载的文件通过节点传输到远程服务器(理想情况下具有相同的文件名)

我想在我的app.js服务器上传一个文件,该文件应该将该文件传输到像我的upload.js服务器这样的跨域服务器.

完整代码可在以下链接中找到

upload.js服务器正在运行.我的问题是app.js服务器.请求似乎能够传输文件(https://github.com/request/request#streaming).但是我不懂它.我总是得到:我的app.js中的[错误:协议无效]

最重要的是这条线:

fs.createReadStream(file.path).pipe(request.post('localhost:4000/upload'))
Run Code Online (Sandbox Code Playgroud)

我将post更改为put并在我的upload.js中post方法也放,但它会导致相同的错误.

我的目标是将文件从html页面上传到localhost:3000/upload,将文件管道传输到localhost:4000/upload(理想情况下具有相同的文件名).但我没有得到它的工作(这篇文章没有帮助我).

app.js:

var express = require('express')
    , multiparty = require('multiparty')
    , request = require('request')
    , fs = require('fs')
    , util = require('util')
    , http = require('http');

var app = express();
app.use('/static', express.static('static'));

process.on('uncaughtException', function (err) {
    console.log(err);
});

app.get('/', function (req, res) {
    res.redirect('static/index.html');
});

app.post('/upload', function(req, res, next){

    //https://github.com/request/request#streaming

    var form = new multiparty.Form();

    form.parse(req, function(err, fields, files) {
        res.writeHead(200, {'content-type': 'text/plain'});
        res.write('received upload:\n\n');
        res.end(util.inspect({fields: fields, …
Run Code Online (Sandbox Code Playgroud)

file-upload node.js

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

file-upload ×1

node.js ×1