liamks / delivery.js Goto Github PK
View Code? Open in Web Editor NEWAsynchronous Bidirectional File Transfers For Node.js via Socket.IO
Asynchronous Bidirectional File Transfers For Node.js via Socket.IO
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
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?
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
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
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 !
I tried uploading 120 MB file and it failed .Is there any other way around to get it done.
Please, could someone show me how to do it? How can I import the library into TypeScript?
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.
Everything is in the title :)
Thanks
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.
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?
Dear all,
i can't send file over 2MB, Below 2MB is fine.
the error in console:
GET http://myadomain.com/socket.io/?EIO=3&transport=polling&t=1434728534620-21&sid=6B8AVAkFOYEiBx75AAAu 503
POST http://mydomain.com/socket.io/?EIO=3&transport=polling&t=1434728594780-22&sid=6B8AVAkFOYEiBx75AAAu 400 (Bad Request)
Is it true if delivery.js can't send large 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?
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')
}
});
});
});
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.
Please put Delivery on Bower (with the same name used on NPM), for client->server it would make dependency management simpler.
Thank you
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.
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!
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)
I want to upload multiple file to server. But Delivery doesn't active;
Help me, please! Thanks!
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.
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
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");
};
});
});
}
Sending Image (1/4)...
Sending Image (2/4)...
Sending Image (3/4)...
Sending Image (4/4)...
-----------------------------------
Images Uploaded Successfully!
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!");
});
}
}
I haven't access to "delivery.js" file, how can I import it in my html without 404 error?
https://github.com/liamks/Delivery.js/blob/master/lib/client/delivery.js#L47
it seems dangerous
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?
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.