Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ac4310635d6087cc6fe98d2cc27e27d9 to your computer and use it in GitHub Desktop.
Save anonymous/ac4310635d6087cc6fe98d2cc27e27d9 to your computer and use it in GitHub Desktop.
in app.js file I have the below code for mysql connection
var mysql = require("mysql");
var myConnection = require('express-myconnection');
app.use(myConnection(mysql, {
host: conf.host,
user: conf.dbUser,
password: conf.dbPassword,
database: conf.dbName
}, 'pool'));
in functions.js file I have file upload functionality. Sample code below
var upload = require('../lib/JqueryFileUploadMiddleware');
module.exports = function(app) {
var conf = app.get('conf');
upload.uploadFile = upload.fileHandler({
tmpDir: conf.temp,
uploadDir: conf.uploadDir,
uploadUrl: conf.uploadUrl,
maxPostSize: 11000000000, // 11 GB
minFileSize: 1,
maxFileSize: 10000000000, // 10 GB
acceptFileTypes: /.+/i
});
// bind event
upload.on('begin', function (fileInfo, reqs, resp) {
var fileType = resp.req.fields.file_type;
var originalFileName = fileInfo.name;
var renamedFilename = file.fileRename(fileInfo,fileType);
/*renaming the file */
fileInfo.name = renamedFilename;
/*start: log the details in database;*/
var utcMoment = conf.moment.utc();
var UtcSCPDateTime = new Date( utcMoment.format() );
var activityData = {
activity_type : conf.LIST_UPLOAD_BEGIN,
username : test ,
message : 'test has started the upload process for the file',
activity_datetime : UtcSCPDateTime
};
reqs.params.activityData = activityData;
req.getConnection(function(err,connection) {
var dbData = req.params.activityData;
var activity_type = dbData.activity_type;
console.dir("[ Connection ID:- ] "+connection.threadId+' ] [ Activity type:- ] '+activity_type);
var insertQuery = connection.query("INSERT INTO tblListmanagerActivityLog SET ? ",dbData, function(err, result) {
if (err) {
console.log("Error inserting while performing insert for activity "+activity_type+" : %s ",err );
} else {
console.log('Insert successfull');
}
});
});
/*end: log the details in database;*/
});
/*convert file from dos to unix after file upload is complete */
upload.on('end', function (fileInfo,request,response) {
/*start: log the details in database;*/
var utcMoment = conf.moment.utc();
var UtcSCPDateTime = new Date( utcMoment.format() );
var activityData = {
activity_type : conf.LIST_UPLOAD_COMPLETE,
username : 'test' ,
message : 'The list '+fileInfo.name+' (Uploader : test') is successfully uploaded.',
activity_datetime : UtcSCPDateTime
};
request.getConnection(function(err,connection) {
var dbData = request.params.activityData;
var activity_type = dbData.activity_type;
console.dir("[ Connection ID:- ] "+connection.threadId+' ] [ Activity type:- ] '+activity_type);
var insertQuery = connection.query("INSERT INTO tblListmanagerActivityLog SET ? ",dbData, function(err, result) {
if (err) {
console.log("Error inserting while performing insert for activity "+activity_type+" : %s ",err );
} else {
console.log('Insert successfull');
}
});
});
/*end: log the details in database;*/
-----------------------
------------------------
----------------------------
});
/* upload end callback done */
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment