Description
Hello
I have a weird problem, I'm working on creating a one interface to permit only load one file, it works well when I load the file for the first time, but when I load another file after deleting the previous file, this new file is uploaded twice, and then if I closed the view and open again to load a new file, the file is uploaded three times, I'm using this code to upload in the server.
app.use('/upload', function(request, response, next){
upload.fileHandler({
uploadDir: function(){
return __dirname + '/site/public/uploads/' + request.session.login;
},
uploadUrl: function(){
return '/site/uploads/' + request.session.login;
}
})(request, response, next);
upload.on('begin', function(fileInfo){
logger.debug("starting loading a file");
var ext = fileInfo.name.substr(fileInfo.name.lastIndexOf('.') + 1);
var newFile = shortId.generate() + '.' + ext;
request.session.newFile = newFile;
logger.debug("file uploaded " + request.session.newFile + " - " + newFile);
fileInfo.name = newFile;
});
upload.on('end', function(fileInfo){
logger.debug('file uploaded ' + fileInfo.name);
});
});
I would appreciate any suggestion.