OSDN Git Service

implemented simple file uplaod through websocket
[eos/zephyr.git] / server / ws / index.js
1 'use strict'
2
3 var fs = require('fs')
4
5 module.exports = function(io) {
6     io.on('connection', function(socket) {
7         console.log("websocket was connected")
8         /*
9             array include obj
10             {
11                 data: blob,
12                 name: filename,
13                 dir : directory,
14             }
15         */
16         socket.on('upload', function(array) {
17             array.forEach(function(file) {
18                 var path = file.dir+'/'+file.name
19                 fs.writeFileSync(path, file.data)
20             })
21             socket.emit('done', 'success')
22         })
23     })
24 }