Reputation: 25
how can i send a file path through socket.io i.e
genrally we use
socket.emit("sendpath","hi" );
socket.on("sendpath",function()
{
console.log("hi")
}
to emit a file path i.e a pdf file which is in my c drive how can that happen
path is :-"C:\xampp\248.pdf"
Upvotes: 1
Views: 3564
Reputation: 1101
I'm not completely sure I understand your question, but I'm going to assume that you want the contents of a file, given the path to that file, provided as a Socket.IO event.
// var fs = require("fs");
socket.on("sendpath",filepath){
fs.readFile(filepath,function(error, filedata){
if(error) throw error;
else socket.emit("sendfile", filedata.toString() );
});
});
Reference: http://nodejs.org/api/fs.html#fs_fs_readfile_filename_encoding_callback
Upvotes: 1