Giter VIP home page Giter VIP logo

delivery.js's Introduction

Delivery.js (Experimental)

Bidirectional File Transfers For Node.js via Socket.IO

Sending files to the server, and pushing files to the client should be as easy as possible. Delivery.js uses Node.js and Socket.IO to make it easy to push files to the client, or send them to the server. Files can be pushed to the client as text (utf8) or base64 (for images and binary files).

Install

npm install delivery -g

Browser JavaScript

delivery.js can be found within lib/client.

Examples

Sending a File To a Server (Client is a browser)

Server-side code

var io  = require('socket.io').listen(5001),
    dl  = require('delivery'),
    fs  = require('fs');

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

Client-side code

$(function(){
  var socket = io.connect('http://0.0.0.0:5001');
  
  socket.on('connect', function(){
    var delivery = new Delivery(socket);

    delivery.on('delivery.connect',function(delivery){
      $("input[type=submit]").click(function(evt){
        var file = $("input[type=file]")[0].files[0];
        var extraParams = {foo: 'bar'};
        delivery.send(file, extraParams);
        evt.preventDefault();
      });
    });

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

Pushing a File to a Client (Client is a browser)

Server-side code

var io  = require('socket.io').listen(5001),
    dl  = require('delivery');

io.sockets.on('connection', function(socket){
  var delivery = dl.listen(socket);
  delivery.on('delivery.connect',function(delivery){

    delivery.send({
      name: 'sample-image.jpg',
      path : './sample-image.jpg',
      params: {foo: 'bar'}
    });

    delivery.on('send.success',function(file){
      console.log('File successfully sent to client!');
    });

  });
});

Client-side code

$(function(){
  var socket = io.connect('http://0.0.0.0:5001');
  
  socket.on('connect', function(){
    var delivery = new Delivery(socket);

    delivery.on('receive.start',function(fileUID){
      console.log('receiving a file!');
    });

    delivery.on('receive.success',function(file){
      var params = file.params;
      if (file.isImage()) {
        $('img').attr('src', file.dataURL());
      };
    });
  });
});

Transfer files between two servers

Receive file

io.sockets.on('connection', function(socket){
  
  var delivery = dl.listen(socket);
  delivery.on('receive.success',function(file){
		
    fs.writeFile(file.name, file.buffer, function(err){
      if(err){
        console.log('File could not be saved: ' + err);
      }else{
        console.log('File ' + file.name + " saved");
      };
    });
  });	
});

Send file

socket.on( 'connect', function() {
  log( "Sockets connected" );
		
  delivery = dl.listen( socket );
  delivery.connect();
	
  delivery.on('delivery.connect',function(delivery){
    delivery.send({
      name: 'sample-image.jpg',
      path : './sample-image.jpg'
    });

    delivery.on('send.success',function(file){
      console.log('File sent successfully!');
    });
  });
	
});

API

Server Functions

Importing delivery.js

dl = require('delivery');

Listen to the socket

var delivery = dl.listen(socket);

Listening to delivery.js events - delivery.on('event',fn)

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

Sending a file

delivery.send({
  name: 'fileName.png',
  path: 'path/to/file/fileName.png'
});
delivery.sendAsText({
  name: 'fileName.txt',
  path: 'path/to/file/fileName.txt'
});

Server Events

'delivery.connect'

delivery.connect is called when a client connects to the server.

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

'receive.start'

receive.start is called when the server starts receiving a file. The callback function takes a filePackage object that describes the file being sent.

delivery.on('receive.start',function(filePackage){
  console.log(filePackage.name);
});

'receive.success'

receive.success is called once the file has been successfully reveived by the server. The callback function takes a filePackage.

delivery.on('receive.success',function(file){
    fs.writeFile(file.name,file.buffer, function(err){
      if(err){
        console.log('File could not be saved.');
      }else{
        console.log('File saved.');
      };
    });
  });

'file.load'

file.load is called after .send() is called and immediately after the file is loaded. The callback function takes a filePackage.

delivery.on('file.load',function(filePackage){
  console.log(filePackage.name + " has just been loaded.");
});

'send.start'

send.start is called after .send() is called and immediately after the file begins being sent to the client. The callback function takes a filePackage.

delivery.on('send.start',function(filePackage){
  console.log(filePackage.name + " is being sent to the client.");
});

'send.success'

send.success is called after .send() is called and once confirmation is received form the client that the the file sent was successfully received. The callback function takes the uid of the file that was sent.

delivery.on('send.success',function(uid){
  console.log("File successfully sent!");
});

FilePackage

FilePackage objects encapsulate files and includes a text representation (utf8), or base64 representation of the file. They also include the file's meta data, including name, size and mimeType.

filePackage.isImage()

returns true if the file has a corresponding mime type that is an image. It is possible that this method could return false if your file is an image, but does not have a mimetype, or does not have a mimetype of image/gif, image/jpeg, image/png, image/svg+xml, image/tiff. Look for var imageFilter within delivery.js if you'd like to add additional mimetypes.

filePackage.isText()

returns true if the server used sendAsText().

filePackage.text()

returns the text representation of the file sent. If the file has been base64 encoded it returns the base64 encoded version of the file.

filePackage.dataURL()

returns the base64 representation of the file prefixed with the data and mimetype necessary to display an image within <img src=''>.

Client

Include delivery.js in your html file

<script src="/js/delivery.js"></script>

Events

Client events mirror those on the server, see server events above for more details.

##License

Delivery.js is released under the MIT license:

http://www.opensource.org/licenses/MIT

Road Map

  1. Incorporating feedback from other developers!
  2. Breaking files into pieces to help transfer larger files.
  3. md5 hash file and confirm the hash when a file has been received.
  4. ?

delivery.js's People

Contributors

liamks avatar troyth avatar zectbynmo avatar fjdelarubia avatar akondas avatar giantalbi avatar c272 avatar marcbachmann avatar

Stargazers

Krzysztof Zawisล‚a avatar Karl Chen avatar Grzegorz Szwyngiel avatar Mohamed Achaq avatar Wamy avatar Adrian Baumgart avatar ่€ฟใ€€ๅ‚‘็„ถ avatar Hazem Hussein avatar Bhushan Wagh avatar xw avatar LUรS CARLOS DE SOUZA  MENEZES avatar Louis t.b avatar bhaskar sengupta avatar Pablo Bion  avatar Abid Hasan avatar wxnet2013 avatar David MiZak avatar George Kurobara Benjamin avatar Yossarian avatar Garvit chhabra avatar Mahdi Pakravan avatar Frank Lemanschik avatar luo jiyin avatar Rajkumar avatar daben1990 avatar TuฤŸrul Altun avatar ax4 avatar  avatar  avatar  avatar VaDi avatar Shivam Bansal avatar Quang Phan avatar Nguyแป…n Quang HฦฐแปŸng avatar Fabian Zbinden avatar  avatar Cristian Tatu avatar Pooria Atarzadeh avatar GaryChen, PYChen avatar Morgan Brown avatar Andres Separ avatar  avatar  avatar Anuj Raval avatar  avatar Amin Akbari avatar Vidar Eldรธy avatar Jean Barriere avatar Vithal Reddy avatar Gรฉraud Henrion avatar Krittin Phornsiricharoenphant avatar Mr. Simple J avatar Robert M. Hall avatar netop://ใ‚ฆใ‚จใƒ avatar  avatar Abhishek Chakravarty avatar Josh Ouyang avatar  avatar Bruno Cรกnepa avatar Jason Herald avatar Amal Karunarathna avatar Ishan Marikar avatar Anthony avatar Josh Miller avatar Wesley  avatar Akshay avatar Sumith Jitta avatar Christian Renninger avatar Najm Sheikh avatar Brennan Mackay avatar Ta No Bi avatar Lee avatar mskang avatar Cx01 avatar  avatar Srijan Shukla avatar masaichi avatar  avatar Magda Kordo avatar Mike Tobia avatar Rajika Imal avatar Zsombor Parรณczi avatar Shmuli avatar  avatar DUNCAN MAK avatar Sze Ka Wai Raymond avatar  avatar Victor Truong avatar Jevo avatar geekrobo avatar Nathanaรซl Lรฉcaudรฉ avatar Cristian Pascottini avatar GEOMETRYBASE avatar Benedikt Rรถtsch avatar Logan avatar Simranjit Butalia avatar Lajpat Shah avatar Neha Kadam avatar Michaล‚ Stocki avatar Vishal Isharani avatar

Watchers

 avatar yury avatar Zach Baker avatar  avatar James Cloos avatar Krister Kari avatar dai_yamashita avatar Codedaiquiri avatar JSeverywhere avatar Ingwie Phoenix avatar Guoliang Wang avatar Guanglin An avatar Andres Separ avatar Standa Vรญtek avatar ttquoccuong avatar  avatar SyysBiir avatar Raaj Kanchan avatar

delivery.js's Issues

Server to Client File Transfer not working. No errors

I have had the Client(chrome) to Server file transfering working for a while and recently needed to transfer files back to the Client.

I set up the file.load, send.start, and send.success event handlers and then call delivery.send(data).

First send.start is dispatched and then file.load. (I would think we would need to load the file before sending it... but w/e)

That's it. Nothing else ever happens.

Inspecting the Server delivery object I see that an entry has been added to delivery.sending

Client is never contacted in any way though. (I think, as the client's delivery.receiving object never has an entry added)

Furthermore I have noticed that the Client's delivery.connected is true (as expected)
but the Server's delivery.connected is NEVER true... (even in the delivery.connect event)

Not sure if the connected var actually does anything cause the server still receives files no problem.

Help please,
Thanks,
Ryan

delivery.send : mime.lookup is not a function

Hello,

I have this error :

/node_modules/delivery/lib/delivery.server.js:86
  this.mimeType = mime.lookup(this.path);
                       ^

TypeError: mime.lookup is not a function
    at FilePackage.getMimeType (/opt/A7/node_modules/delivery/lib/delivery.server.js:86:24)
    at new FilePackage (/opt/A7/node_modules/delivery/lib/delivery.server.js:58:10)
    at Delivery.send (/opt/A7/node_modules/delivery/lib/delivery.server.js:165:21)
    at /opt/A7/index.js:45:15
    at ChildProcess.exithandler (child_process.js:268:7)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:915:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)

It happens when I use delivery.send on server side and it seems to be a module problem.

Can you help me please ?

Thanks !

Tracking progress

Hey.

Is it possible to track the upload progress so I can report it back to my client as a progress bar? My scenario is sending from a browser to the server.

Thanks!

Server to server transfer crashes recipient node process

Hello, I'm attempting to push a .jpg file from one machine to another server-to server via delivery. I am seeing that upon receiving the image file, when I try to write the buffer to disk, the server side totally crashes. It's as if the try cach wasn't even there!

delivery.on('receive.success', function(file){
console.log('receive.success',file);
try{
console.log('attempting to write buffer to disk');
fs.writeFile(file.name, file.buffer, function(err){
*** crashes right here. reguardless of being in a try catch ***

below is my console output:

Zachrys-MacBook-Pro:whiteboard zbaker$ node server.js
info - socket.io started
debug - client authorized
info - handshake authorized a9QKkyvdNzI_W_YW4cXM
debug - setting request GET /socket.io/1/websocket/a9QKkyvdNzI_W_YW4cXM
debug - set heartbeat interval for client a9QKkyvdNzI_W_YW4cXM
debug - client authorized for
debug - websocket writing 1::
debug - client authorized for /imgPoster
debug - websocket writing 1::/imgPoster
New connection from
debug - websocket writing 5::/imgPoster:{"name":"delivery.connect","args":[""]}
debug - websocket writing 5::/imgPoster:{"name":"send.success","args":["9b93ecdd-d814-4ed9-8342-0f5d1e2eb377"]}
receive.success { name: 'macbook1-1374974760515.jpg',
pubSub: { channels: { 'receive.success': [Object], 'file.load': [Object] } },
size: undefined,
data: '/9j/4UGYRXhpZgAASUkqAAgAAAAJAA8BAgAGAAAAegAAABABAgAcAAAAgAAAABIBAwABAAAAAQAAABoBBQABAAAAoAAAABsBBQABAAAAqAAAACgBAwABAAAAAgAAADIBAgAUAAAAsAAAABMCAwABAAAAAgAAAGmHBAABAAAAxAAAAFAlAABDYW5vbgBDYW5vbiBFT1MgRElHSVRBTCBSRUJFTCBYU2kAAAAAAEgAAAABAAAASAAAAAEAAAAyMDEyOjExOjE0IDE1OjEwOjQ2AB8AmoIFAAEAAAA+AgAAnYIFAAEAAABGAgAAIogDAAEAAAAAAAAAJ4gDAAEAAACQAQAAAJAHAAQAAAAwMjIxA5ACA
{{{{{ and a whole lot more image data }}}}
055q3Hh1ztYsRxxjmvanDXnbtY8Om4KTi1of//Z',
uid: '7af23b0c-7d23-44db-a65a-8cbd88a38cb8',
buffer: <Buffer ff d8 ff e1 41 98 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 09 00 0f 01 02 00 06 00 00 00 7a 00 00 00 10 01 02 00 1c 00 00 00 80 00 00 00 12 01 03 00 01 ...> }
attempting to write buffer to disk

/Users/zbaker/SVN7/projects/whiteboard/node_modules/delivery/lib/delivery.server.js:125
pubSub.publish('receive.start',file.uid);
^
ReferenceError: pubSub is not defined
at Socket. (/Users/zbaker/SVN7/projects/whiteboard/node_modules/delivery/lib/delivery.server.js:125:5)
at Socket.EventEmitter.emit as $emit
at SocketNamespace.handlePacket (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/namespace.js:335:22)
at Manager.onClientMessage (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/manager.js:488:38)
at WebSocket.Transport.onMessage (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/transport.js:387:20)
at Parser. (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/transports/websocket/hybi-16.js:39:10)
at Parser.EventEmitter.emit (events.js:95:17)
at finish (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/transports/websocket/hybi-16.js:288:16)
at Parser.expectHandler (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/transports/websocket/hybi-16.js:299:15)
at Parser.add (/Users/zbaker/SVN7/projects/whiteboard/node_modules/socket.io/lib/transports/websocket/hybi-16.js:466:24)

Max transfer size?

I'd like to use Delivery to send .zip files that are up to ~500mb in size between servers. Does Delivery have any known issues or limitations for files of this size?

RegEx compatibility

Just a suggestion for the browser-side client. To get maximum browser compatibility for your isImage regex, you may want to construct it with new RegExp('...here...', 'i') because the flags aren't universally supported using a regex-literal.

Download file?

The example source code shows how to display an image that was downloaded to the client (browser) but how would I allow the user to download the (binary, not an image) file that gets sent from the server to the browser?

Mime Types Still Broken. [NPM VERSION]

Upon initiating a file transfer, this error is thrown now, I believe a package you were depending on has changed.

this.mimeType = mime.lookup(this.path);
^

TypeError: mime.lookup is not a function

TypeError: Cannot read property 'uid' of null

Using the following code to send a file from a node.js backend:

var ioClient = require('socket.io-client');
var socket = ioClient.connect('http://' + host);
socket.on('connect', function() {
    delivery = dl.listen(socket);
    delivery.connect();
    delivery.on('delivery.connect', function(delivery){
        delivery.send({
            name: file_name,
            path : file_path
        });
        delivery.on('send.success', function(file){
            // something....
        });
    });
});

To this server:

var io  = require('socket.io').listen(5001);
io.sockets.on('connection', function(socket){
  var delivery = dl.listen(socket);
  delivery.on('receive.success',function(file){
      // something...
  });
});

Results the following error:

2016-01-08T23:59:06.846533210Z Missing error handler on `socket`.
2016-01-08T23:59:06.846544375Z TypeError: Cannot read property 'uid' of null
2016-01-08T23:59:06.846547082Z     at Array. (/src/node_modules/delivery/lib/delivery.server.js:124:42)
2016-01-08T23:59:06.846549676Z     at PubSub.publish (/src/node_modules/delivery/lib/delivery.server.js:27:11)
2016-01-08T23:59:06.846551777Z     at Socket. (/src/node_modules/delivery/lib/delivery.server.js:155:18)
2016-01-08T23:59:06.846553851Z     at emitOne (events.js:77:13)
2016-01-08T23:59:06.846555769Z     at Socket.emit (events.js:169:7)
2016-01-08T23:59:06.846557679Z     at Socket.onevent (/src/node_modules/socket.io/lib/socket.js:335:8)
2016-01-08T23:59:06.846559655Z     at Socket.onpacket (/src/node_modules/socket.io/lib/socket.js:295:12)
2016-01-08T23:59:06.846561625Z     at Client.ondecoded (/src/node_modules/socket.io/lib/client.js:193:14)
2016-01-08T23:59:06.846564037Z     at Decoder.Emitter.emit (/src/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
2016-01-08T23:59:06.846566300Z     at Decoder.add (/src/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)

The file json data is the following received on the server side:

{"name":"filename.txt","pubSub":{"channels":{"receive.success":[null,null],"file.load":[null]}},"data":"
...... FILE_DATA_HERE.......
]}}

Is there anything I am missing here?

Sending larger files throws JS error

Uploading a larger file - (video file 300MB) throws the following error

delivery.js:66 Uncaught RangeError: Invalid string lengthdelivery.js:66
reader.onload

I'm guessing deliveryjs dosen't chunk the data?

socket.io gets Disconnected

Server to Server Communication issue (#20)

Receiver Node LOG

Connected to Server socket.
File 0.jpg saved
File 1.jpg saved
File 2.jpg saved
TypeError: Cannot read property 'uid' of null
    at Array.<anonymous> (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\
delivery\lib\delivery.server.js:124:42)
    at PubSub.publish (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\del
ivery\lib\delivery.server.js:27:11)
    at Socket.<anonymous> (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules
\delivery\lib\delivery.server.js:155:18)
    at Socket.emit (events.js:107:17)
    at Socket.onevent (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\soc
ket.io\lib\socket.js:335:8)
    at Socket.onpacket (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\so
cket.io\lib\socket.js:295:12)
    at Client.ondecoded (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\s
ocket.io\lib\client.js:193:14)
    at Decoder.Emitter.emit (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modul
es\socket.io\node_modules\socket.io-parser\node_modules\component-emitter\index.
js:134:20)
    at Decoder.add (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\socket
.io\node_modules\socket.io-parser\index.js:247:12)
    at Client.ondata (C:\xampp\htdocs\iothss\git-iothss\iothss\node_modules\sock
et.io\lib\client.js:175:18)
Socket Disconnected!
File 3.jpg saved

Receive Node Code

function receiveimage(delivery,dir){
    delivery.on('receive.success',function(file){
        fs.writeFile( __dirname + '/img/' + dir + '/' + file.name, file.buffer, function(err){
            if(err){
                console.log('File could not be saved: ' + err);
            }else{
                console.log('File ' + file.name + " saved");
            };
        });
    });
}

Sender Node LOG

Sending Image (1/4)...
Sending Image (2/4)...
Sending Image (3/4)...
Sending Image (4/4)...
-----------------------------------
Images Uploaded Successfully!

Sender Node Code:

function sendimage(delivery,dir){
  for(var i=0;i<4;i++) {
    console.log( "Sending Image (" + (i+1) + "/4)..." );
    delivery.send({
      name: i + '.jpg',
      path: './img/' + dir + '/' + i + '.jpg'
    });

    delivery.on('send.success',function(){
      console.log("File successfully sent!");
    });
  }
}

Server to server connection(compilation error)

var socket = io.connect('http://localhost:5001'),
^
TypeError: undefined is not a function
at Object. (C:\xampp\htdocs\iothss\git-iothss\rpi\server.js:6:17)

at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Modification in delivery.server.js

modified_server

I think two places (shown as a yellow pointer in the above file) are modified to transfer files from server to client. Please check it out.

Upload progress feature

I'd like to be able to show my client how much time is left until the upload is completed. Is there a possibility of implementing this? My scenario would be a browser to server transmission.

Server to Server Seems to Send Data Twice.

I'm trying to use your library to do fast server to server file transfers. I've attempted to use your examples.

receiver.js

var io  = require('socket.io').listen(5001),
    dl  = require('delivery'),
    fs  = require('fs');

io.sockets.on('connection', function(socket){
  var delivery = dl.listen(socket);

  delivery.on('receive.success',function(file){
    fs.writeFile('./data2/' + file.name, file.buffer, function(err){
      if (err) {
        console.log('File could not be saved.', file.uid, file.name);
      } else {
        console.log('File saved.', file.uid, file.name);
      };
    });
  });
});

sender.js

var socket = require('socket.io-client')('http://0.0.0.0:5001');
var dl = require('delivery')
var fs = require('fs')
var async = require('async')

socket.on('connect', function(){
  var delivery = dl.listen(socket);
  delivery.connect()

  console.log('----connected----')

  delivery.on('delivery.connect',function(delsocket){
    console.log('delivery connected')

    delsocket.on('send.success',function(fileUID){
      console.log("file was successfully sent.", fileUID);
    });

    fs.readdir('./data1', function(err, files) {
      async.eachSeries(files, function(f, cb) {
        console.log('called', f)
        delivery.send({
          name: f,
          path: './data1/' + f
        })
        cb()
      })
    })
  });

});

It seems that the loop only does a "delivery.send" once per file, but the send.success triggers twice per file. I've tried listening on the overall delivery for send.success but also on the delivery.connect event too.

----connected----
delivery connected
called 1425339118.sst
called 1425339126.sst
called 1425339135.sst
called thisisanewfile.txt
file was successfully sent. 863defe2-be89-4d24-a1a7-bbba02b87cc6
file was successfully sent. 863defe2-be89-4d24-a1a7-bbba02b87cc6
file was successfully sent. 772296e5-5e7d-4387-a23e-298dd7dd8829
file was successfully sent. 772296e5-5e7d-4387-a23e-298dd7dd8829
file was successfully sent. d783486d-1b63-42f4-99e0-13ec47cbd8fa
file was successfully sent. d783486d-1b63-42f4-99e0-13ec47cbd8fa
file was successfully sent. e6a36bde-1eb9-4dc8-b7e1-e1f7c98ea6da
file was successfully sent. e6a36bde-1eb9-4dc8-b7e1-e1f7c98ea6da

Thanks.

Submit all form inputs

Hi, can this module be used to submit all form elements. inputs and files at the same time?
I need to send 1-3 files and some inputs values at the same time.
I was trying to emit a simple object by using readAsBinaryString and encode it to base64 and send all images along with form data ( {id: 1, file1: base64, file2: base64,otherinput: value ...} ), it works, but i am having problems with 50MB+ files so i'm after a module to do that for me.
Thanks and great job.

Missing error handler and pubSub not defined

Hi,

Thanks a lot for delivery. I've got it working and files are being send (server to server) however I get an annoying error message every time:

Missing error handler on socket.
ReferenceError: pubSub is not defined
at Socket. (/Users/thijsnieuwkoop/node_modules/delivery/lib/delivery.server.js:125:5)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onevent (/Users/thijsnieuwkoop/node_modules/socket.io/lib/socket.js:330:8)
at Socket.onpacket (/Users/thijsnieuwkoop/node_modules/socket.io/lib/socket.js:290:12)
at Client.ondecoded (/Users/thijsnieuwkoop/node_modules/socket.io/lib/client.js:193:14)
at Decoder.Emitter.emit (/Users/thijsnieuwkoop/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
at Decoder.add (/Users/thijsnieuwkoop/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)
at Client.ondata (/Users/thijsnieuwkoop/node_modules/socket.io/lib/client.js:175:18)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onPacket (/Users/thijsnieuwkoop/node_modules/socket.io/node_modules/engine.io/lib/socket.js:99:14)
at emitOne (events.js:77:13)
at XHR.emit (events.js:169:7)
at XHR.Transport.onPacket (/Users/thijsnieuwkoop/node_modules/socket.io/node_modules/engine.io/lib/transport.js:91:8)
at callback (/Users/thijsnieuwkoop/node_modules/socket.io/node_modules/engine.io/lib/transports/polling.js:202:10)

What is going on?

Server side:
io.sockets.on('connection', function(socket){
var delivery = dl.listen(socket);
delivery.on('receive.success', function(file){
fs.writeFile(file.name, file.buffer, function(err2){
if (err2){
console.log('File could not be saved: '+err2);
} else {
console.log('File '+file.name+' saved')
}
});
});
});

fails for large file.

I tried uploading 120 MB file and it failed .Is there any other way around to get it done.

Extra params don't seem to be sent

So far, Delivery.js has amazed me when it comes to simplicity of sending files through Socket.io. Props for making such a module! :-)

When I use delivery.send(file,extraParams) (extraParams being an object, as described in the readme), and I check the content of file on the server after receive.succes, I don't see the property params (I used Object.keys() to retrieve all the keys from the file-object), and reading file.params returns undefined.

I'd like to send meta-data with my application. Do you have an idea how I can include this meta data (or params) after all? I tried altering Delivery.prototype.send, FilePackage and FilePackage.prototype.prepBatch; but with no avail so far. Could you give me a pointer for fixing this, or help me out here?

Thanks in advance for taking a look at it!

Bower

Please put Delivery on Bower (with the same name used on NPM), for client->server it would make dependency management simpler.
Thank you

Can use with angular js

I want to Create web app that send file from node js to Client that use angular js
Can i use delivery to send file ??

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.