Upload multiple files using Angular Mongodb Nodejs

ANGULAR

//inject angular file upload directives and services.
var app = angular.module('fileUpload', ['ngFileUpload']);

app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadFiles = function (files) {
$scope.files = files;
if (files && files.length) {
Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
files: files
}
}).then(function (response) {
$timeout(function () {
$scope.result = response.data;
});
}, function (response) {
if (response.status > 0) {
$scope.errorMsg = response.status + ': ' + response.data;
}
}, function (evt) {
$scope.progress =
Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
};
}]);

HTML

Upload on file select

Files:

  • {{f.name}}


{{errorMsg}}

NODEJS

var multipartyc = require('connect-multiparty'), multipartyMiddlewarec = multipartyc({uploadDir: '/var/www/html/workfromhome/atachedfiles'});

app.post('/uploadfilerequirements', multipartyMiddlewarec, function (req, res) {

//var stra = req.files.picturea.path;
// var pictureapath = stra.substring(stra.lastIndexOf("/") + 1, stra.length);

var arraystringfilestosave=" xxxx";

//console.log(req.files.files[0].path);

//

var i;
for (i = 0; i < req.files.files.length; i++) { var stra=req.files.files[i].path; var filepath = stra.substring(stra.lastIndexOf("/") + 1, stra.length); arraystringfilestosave += filepath+"#"; } console.log(arraystringfilestosave); var current_millies = new Date().getTime(); MongoClient.connect(url, function (err, db) { if (err) throw err; var dbo = db.db("workfromhome"); const uuidv1 = require('uuid/v1'); var contractuid = uuidv1(); var newcontract = {uid:contractuid, emailserviceprovider:req.body.emailserviceprovider }; dbo.collection('contracts').insertOne(newcontract, function (err, result) { if (err) { res.send('Error'); } else { res.send('true'); } }); }); });

Mongodb nodejs how to update nested array object

app.post('/openmessage', function (req, res) {

MongoClient.connect(url, function (err, db) {
if (err) throw err;

var dbo = db.db("workfromhome");

MongoClient.connect(url, function (err, db) {
if (err) throw err;

dbo.collection('users').updateOne({'messages.uid':req.body.uid},{'$set': {
'messages.$.readed': 'yes'
}}, function (err, result) {

if (err) {
console.log(err);
res.send('error');
db.close();
} else {
console.log("success");
res.send('success');
db.close();
}
});
});
});
})

MONGODB NODEJS increment in 1 integer row

app.get('/facebookads', function (req, res) {

MongoClient.connect(url, function (err, db) {
if (err) throw err;

var dbo = db.db("EggClicker");

dbo.collection('Facebookads').findOneAndUpdate({fbkads: "placementone"},{ $inc: { "click" : 1 } },function (err, result) {

if (err) {
console.log("entra a error")
res.send('error');
}
else if (!result) {
console.log("entra a notmatch")

res.send('notmatch');

} else {

console.log(result+" done");

res.send(result+" done");
//res.send(result);
}

db.close();

});
});
})

Unity JSON array with JsonParser from nodejs and mongodb

StartCoroutine(GetTotalClicks(PlayerPrefs.GetString ("email")));

IEnumerator GetTotalClicks(string email)
{
var url = "http://www.xxxxxxx.com:8088/gettotalclicks";
var form = new WWWForm();
form.AddField("email", email);

WWW www = new WWW(url, form);

yield return www;

if (www.error == "" || www.error == null) {

UnityEngine.Debug.Log(www.text);

string JSONToParse = "{\"Items\":" + www.text + "}";

Player[] player = JsonHelperb.FromJson(JSONToParse);

Debug.Log (player [0].clicks);
Debug.Log (player [1].clicks);
}
else
{
UnityEngine.Debug.Log("WWW Error: " + www.error);
}
}

[System.Serializable]
public class Player
{

public string _id;
public string email;
public string date;
public string clicks;
public string done;
public string deviceid;
public string eggfinished;

}

public static class JsonHelperb
{
public static T[] FromJson(string json)
{
Wrapper wrapper = JsonUtility.FromJson>(json);
return wrapper.Items;
}

public static string ToJson(T[] array)
{
Wrapper wrapper = new Wrapper();
wrapper.Items = array;
return JsonUtility.ToJson(wrapper);
}

public static string ToJson(T[] array, bool prettyPrint)
{
Wrapper wrapper = new Wrapper();
wrapper.Items = array;
return JsonUtility.ToJson(wrapper, prettyPrint);
}

[System.Serializable]
private class Wrapper
{
public T[] Items;
}
}

Connect Nodejs Mongodb and Angular with https

nodejs file

var fs = require('fs');
var https = require('https');
var privateKey = fs.readFileSync('certs/www.beetalkweb.com.key', 'utf8');
var certificate = fs.readFileSync('certs/bba86444d2e3bca1.crt', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://Fespunaa:1982Fesp1982@127.0.0.1:27017/";

var bodyParser = require('body-parser')

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.get('/', function(req, res, next) {
// Handle the get for this route
res.render('index', {});

});

app.post('/', function(req, res, next) {
// Handle the post for this route
});

app.get('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

app.post('/conne', function (req, res) {

MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("myads");

dbo.collection("ads").find({"ad_name":"adname"}).toArray(function(err, result) {

if (err) throw err;

res.send(result);

db.close();
});
});

})

var httpsServer = https.createServer(credentials, app);
httpsServer.listen(8443);

Angular / html file


WeTalk



{{content}}


ver en editar texto innterior