jquery - How to return the new files name when set defer=true in express.bodyParser -


express config:

server.configure(function () { server.use(express.bodyparser({     keepextensions:true,     limit:100000000,     defer:true,     uploaddir: "d:/"}) ); 

upload controller:

exports.upload = function(req, res){     req.form.on('progress',function(bytesreceived, bytesexpected){         res.send({loaded: bytesreceived, total: bytesexpected});     });     req.form.on('complete',function(){         if(!path.existssync(uploaddir)){             mkdirp(uploaddir, function (err) {                 if (err) console.error(err)                 saveimg(req, res);             });         } else {             saveimg(req, res);         }     }); };  var saveimg = function(req, res) {     var scrname =  req.files.files[0].path;     var distname = uploaddir + uuid.v4() + '.png';     var gm = require('gm');     gm(scrname)         .resize(1000, 1000)         .autoorient()         .write(distname, function (err) {             fs.unlink(scrname);             // res.send({distname: distname});         }); } 

although not call "res.send({distname: distname})", client reponse when upload success, how can new image names in jquery codes below:

$('#fileupload').fileupload({         url: vari.apipath + 'upload',         datatype: 'json',         done: function (e, data) {             console.log(data.distname);          },         progressall: function (e, data) {             var progress = parseint(data.loaded / data.total * 100, 10);             $('#progress .progress-bar').css(                 'width',                 progress + '%'             );         }     }).prop('disabled', !$.support.fileinput)         .parent().addclass($.support.fileinput ? undefined : 'disabled'); 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -