I want know how to send files through socket (socket.io) with node.js, this is for Phonegap mobile app.
Asked
Active
Viewed 7,062 times
3
-
4Did you even try googling this? I saw a bunch of promising results with `socket.io send file` as my query, including a module designed to do *exactly* what you are asking for ([delivery.js](https://npmjs.org/package/delivery)) – Chad Sep 22 '13 at 05:46
-
Please be aware that files are sent text-encoded and not in binary form. – Kurt Pattyn Sep 22 '13 at 14:10
-
Although socket.io doesn't support sending binary data, it can send string in any charset. With FileReader, you can read binary into strings and sending it directly without encoding it to base64. (actually it's in ISO/IEC 8859-1 latin). You can do with native iOS library as well. – Tony Chen Sep 22 '13 at 15:18
1 Answers
2
I'm not sure if phonegap can use socket.io client javascript library, if yes, then it's easy. You can use Deliver.js as Chad suggested. It's based on utf8/base64.
Or you can refer to this How to Create a Resumable Video Uploader in Node.js. It's got a demo.
If you want to use native iOS library, take a look at this: socket.IO-objc, it's an iOS version of socket.io client library, can communicate with socket.io server quite well. You can build a similar file transfer logic based on this library.

Tony Chen
- 1,804
- 12
- 13
-
Hello, i did a app with node.js and socket.io and works very well, but i did can't send files, for now i am thinking on get base4 of file, and make a chunks of 8bytes, then try to send chunk by chunk, with implementing a bucle for this. – Javier Gomez Sep 23 '13 at 12:24
-
Just saw this: http://stackoverflow.com/questions/10738073/socket-io-phonegap, looks like PhoneGap can load socket.io client lib. So I think you can use delivery.js to send file. Or just build your own file sending logic. – Tony Chen Sep 23 '13 at 14:32