Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用文件-Delivery.js和socket.io发送参数_Node.js_Sockets_File Upload_Socket.io - Fatal编程技术网

Node.js 使用文件-Delivery.js和socket.io发送参数

Node.js 使用文件-Delivery.js和socket.io发送参数,node.js,sockets,file-upload,socket.io,Node.js,Sockets,File Upload,Socket.io,我正在尝试使用nodejs、socket.io和delivery.js上传一个文件。文件上传对我来说很好,但我需要随文件发送一些参数。但我不知道如何才能做到这一点!这是到目前为止我的代码 Client.html var socket = io.connect(); var delivery = new Delivery(socket); function sendFile(){ delivery.on('delivery.connect',function(delivery

我正在尝试使用nodejs、socket.io和delivery.js上传一个文件。文件上传对我来说很好,但我需要随文件发送一些参数。但我不知道如何才能做到这一点!这是到目前为止我的代码

Client.html

var socket = io.connect();

  var delivery = new Delivery(socket);

  function sendFile(){

    delivery.on('delivery.connect',function(delivery){

        var file = document.getElementById("file").files[0];
        var extraParams = {foo: 'bar'};
        delivery.send(file, extraParams); //trying to send the params with file
        return false;
    });

    delivery.on('send.success',function(fileUID){
      alert("file was successfully sent.");
    });

  }
还有我的server.js

io.sockets.on('connection', function(socket){
  var delivery = dl.listen(socket);
  delivery.on('receive.success',function(file){
  // delivery.on('receive.success',function(file,params){<--tried this also

    var params = file.params;
    console.log(params);
    fs.writeFile(file.name,file.buffer, function(err){
      if(err){
        console.log('File could not be saved.');
      }else{
        console.log('File saved.');
      };
    });
  });
});
io.sockets.on('connection',函数(socket){
var delivery=dl.listen(套接字);
delivery.on('receive.success',函数(文件){
//delivery.on('receive.success',函数(文件,参数){