'use strict'
angular.module('zephyrApp')
-.controller('UploadFileModalController', function($scope, $modalInstance, Restangular) {
+.controller('UploadFileModalController', function($scope, $modalInstance, Restangular, socket) {
// To send multipart request from angular, we should set below
var baseUpload = Restangular.all('/api/upload').withHttpConfig({transformRequest: angular.identity})
$scope.upload = function() {
- var fd = new FormData()
- console.log($scope.files)
- /*
- angular.forEach($scope.files, function(file) {
-
- fd.append("dir", $scope.path)
- fd.append("files", file)
-
- baseUpload.customPOST(fd, undefined, undefined, { 'Content-Type': undefined })
- .then(function(status) {
- console.log('File upload', status)
- $modalInstance.close()
- })
- })
- */
+ var array = []
+ angular.forEach($scope.uploadFiles, function(file) {
+ var param = {
+ data: file,
+ name: file.name,
+ dir: $scope.path
+ }
+ array.push(param)
+ })
+ socket.emit('upload', array)
}
- $scope.bindFiles = function(files) {
- $scope.files= files
+ $scope.bindUploadFiles = function(files) {
+ $scope.uploadFiles= files
}
$scope.close = function() {
$modalInstance.close()
}
+
+ socket.on('done', function(msg) {
+ console.log(msg)
+ $modalInstance.close()
+ })
})
});
var io = require('socket.io').listen(server)
-
-io.on('connection', function(socket) {
- console.log("WebSocket was connected")
- })
-
+require('./ws')(io)
exports = module.exports = app;
--- /dev/null
+'use strict'
+
+var fs = require('fs')
+
+module.exports = function(io) {
+ io.on('connection', function(socket) {
+ console.log("websocket was connected")
+ /*
+ array include obj
+ {
+ data: blob,
+ name: filename,
+ dir : directory,
+ }
+ */
+ socket.on('upload', function(array) {
+ array.forEach(function(file) {
+ var path = file.dir+'/'+file.name
+ fs.writeFileSync(path, file.data)
+ })
+ socket.emit('done', 'success')
+ })
+ })
+}